[Solved] Image disappears while linearly transforming it in a function

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
Saa
Regular
Posts: 32
Joined: Tue Aug 20, 2013 7:11 pm
Tumblr: nipahgirl
Contact:

[Solved] Image disappears while linearly transforming it in a function

#1 Post by Saa » Wed Apr 24, 2019 8:03 am

Edit: Figured out the issue! I have no idea why, but when in a transform function, instead of pixels, ypos is calculated in relation to the window size (so, if the window is 1280x720, 1280 is xpos 1.0 and 720 is ypos 1.0). That's why the image disappeared, it was off the screen in pixel 226800.


I need to use Python instead of ATL in an animation, but have no idea how to make that animation be linear (ideally it would be ellastic, but I can settle for linear or try to modify it once I learn how to do it linearly). At the moment this is my code:

Code: Select all

init python:
    import random
    def slotland1a(trans, st, at):
        landing = random.randint(0,3)*15 + 270
        trans.ypos = 315 - (315-landing)*st
        if st>1.0:
            return None
        else:
            return 0

Code: Select all

image slota:
    "slota.png"
    xpos 212
    ypos 315
    block:
        linear 0.5 ypos 270
        ypos 315
        repeat 5
    function slotland1a
    pause 1.0
    repeat
Problem is, while trans.ypos does get the desired values (I checked it on the console), the image completely disappears from the screen while slotland1a runs. I don't understand how that could possibly happen, but it does. (the image isn't visible if ypos is 0, so it could be defaulting to 0, but print trans.ypos always gives out the right values)

Can someone tell me what I'm doing wrong, or show me a different way to do linear warps on python?
Last edited by Saa on Fri Apr 26, 2019 3:05 pm, edited 1 time in total.

User avatar
Saa
Regular
Posts: 32
Joined: Tue Aug 20, 2013 7:11 pm
Tumblr: nipahgirl
Contact:

Re: Image disappears while linearly transforming it in a function

#2 Post by Saa » Fri Apr 26, 2019 10:54 am

I've tried using a while loop:

Code: Select all

def slotland1a(trans, st, at):
        landing = random.randint(0,3)*15 + 270
        while st<1.0:
            trans.ypos = 315 - (315-landing)*st
        return None
But that crashes my game. Whatever's wrong, it has to do with st, but I have no idea why.

I've also tried making a function just to return the landing value, but ATL only calls it once and then uses the same value every time it repeats. ypos has to be change in the transform function, and I can't find a way to do it lineraly...

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: [Solved] Image disappears while linearly transforming it in a function

#3 Post by Remix » Fri Apr 26, 2019 6:24 pm

Even though you solved it... a quick bit of info:

st is always a float ( seconds dot parts of a second ), so when you do the trans.ypos = 315 - (315-landing)*st bit it will always produce a float. You could have tried trans.ypos = int( 315 - (315-landing)*st ) btw
Frameworks & Scriptlets:

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]