Problem with transformations and container images synching

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.
Message
Author
Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Problem with transformations and container images synching

#1 Post by Onishion »

Ok, I'm having a slightly odd problem here. I have a slightly complicated animated image made up of dynamic displayables and containers. It mostly works, but I'm getting this weird glitch. There are two container layers, the "over" and the "under," and they are meant, in this stage at least, to be perfectly synched up, moving and stopping identically. The appear just fine, they start moving just fine, but if I stop them moving again, the "under" layer returns to its correct default position, but the "over" layer stops wherever it is and freezes, which usually means it is now offset from the Under layer. If I then do "something else" like click on a menu option or something that advances the game, it will usually snap into proper place, but even a moment of being in the wrong position is immersion breaking.

Any suggestions as to how I can get the Horse_Over image to return to its default position rather than sticking in place? Or if there are any general suggestions of how to do these same basic things in a different/better way, that could be nice too.

Anyways, here's the relevant code, with some commenting:

Code: Select all

image Horse_Under:     # This combines the base horse body with the "Rider" dynamic image, which is customizable
    contains:
        "images/Horse_body.png" 
    contains:
        "Rider"
        ypos -590
        xpos 180
    xpos -60 
    ypos 120 

image Horse_Over: # This is the head.
    contains:
        "images/Horse_head.png"     
    xpos -60 
    ypos 120 

image Horse_Under_1: #this is a basic movement cycle
    "Horse_Under"       
    ease 1.5 ypos 300 subpixel True    #50
    ease 1 ypos 120 subpixel True  
    repeat

image Horse_Over_1: #this is a basic movement cycle
    "Horse_Over"       
    ease 1.5 ypos 300 subpixel True    
    ease 1 ypos 120 subpixel True 
    repeat
        

image Horse_Animation:  # this is the main image container for the horse and rider.
    contains:
        ConditionSwitch(  #this meant to show the static version if Speed is 0, and the animated version if it is 1.
            "Speed == 0", "Horse_Under",  
            "Speed == 1", "Horse_Under_1",
            "Speed != 0", "images/nothing.png",
            ),           
    contains:
        ConditionSwitch(  
            "Speed == 0", "Horse_Over",  
            "Speed == 1", "Horse_Over_1",
            "Speed != 0", "images/nothing.png",
            ),     
    contains:
        "images/Foreground_mask.png"
        zoom 1.80
        ypos -120
        xpos -475
        
label HorseAnim_Launch:  #This label is called to set up the animation image and place it on the screen.
    $ Speed = 0
    show Horse_Animation:
        zoom .55
        xpos 475
        ypos 120        
    with dissolve    
    return


Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Problem with transformations and container images synchi

#2 Post by Onishion »

Is there any suggestion on this one? I'm pretty sure it's some sort of glitch, because it doesn't start happening right away. The first few times I start and stop the animation, it works fine, with everything returning to its intended rest point, but after 3-4 cycles it will start to glitch, where the under layer returns to its rest point, while the over layer stays exactly where it is in the animation cycle, until I do something to update the screen like open a new menu.

Is there some simple line I could add in to force the screen to update instantly after changing the speed maybe?

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Problem with transformations and container images synchi

#3 Post by trooper6 »

You could try: $ renpy.restart_interaction ()

But I'm no expert on this level of animation.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Problem with transformations and container images synchi

#4 Post by Onishion »

Hmm, no, that didn't do anything, but thanks for the suggestion. I did find a slight workaround, it works if I put:

Code: Select all

show Horse_Animation:
    zoom .55
    xpos 475
    ypos 120 
after each speed change action, but this is kinda clunky. I wish that I understood what was causing the glitch.

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: Problem with transformations and container images synchi

#5 Post by nyaatrap »

Try setting pos/anchor on each contains statement in ATL, or just don't use the contains statement.
The contains statement sometimes behaves unpredictably, so I usually use LiveComposite instead of contains.

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Problem with transformations and container images synchi

#6 Post by Onishion »

Try setting pos/anchor on each contains statement in ATL, or just don't use the contains statement.
The contains statement sometimes behaves unpredictably, so I usually use LiveComposite instead of contains.
If you mean setting them to the Contains statements within the final "Horse_Animation" image, that doesn't work. If I do it that way, it will synch them up, but synch them up a little too well, since it prevents them from moving independently at all.

I could try using Live Composite for it, I use LC for portions of it already, but doesn't that also prevent things from moving around within it? I thought that was the advantage to "contains," that it could group together several differently-moving parts and they could keep moving around.

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: Problem with transformations and container images synchi

#7 Post by nyaatrap »

Code: Select all

image composited = Fixed(animA, animB)
image composited = LiveComposite(animA,animB)
image composited:
    contains:
        animA
    contains:
        animB
All of them should work, but positioning are a bit different among them. I also think it's better to place ConditionSwitch at the top block (not under contains).

[edit] LiveComposite doesn't work with pos, but offset. Fixed should work with both pos and offset. It's more safe to use offset because you show the image with another pos properties, which would cause contradiction.

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Problem with transformations and container images synchi

#8 Post by Onishion »

I'm trying to get Live Composite to work for this, but it just doesn't. I can arrange the pieces, but when I try to shift from the static version to the animated version, the animated version won't move. If I try to use zoom or rotate transforms, it works fine, so it is at least accessing the right animated image, but if I try to use any sort of position-shifting transforms in that animation, it just stays perfectly still. I tried offset, and I went back and tried pos and even anchor, none caused the image to budge. Nothing seems to be overriding the (0,0) tupple built into the LiveComposite.

Here's a stripped down version of the code I'm using for this bit. The actual version has more bits, but none that should be relevant:

Code: Select all

image Horse_Under_1:
    "Horse_Under"
    ease 1 yoffset 100 subpixel True 
    ease 1 yoffset 0 subpixel True  
    repeat

image Horse_Animation = LiveComposite(
        (592,794),        
        (0,0), ConditionSwitch(         
            "Speed == 0", "Horse_Under",  
            "Speed == 1", "Horse_Under_1",
            ),  
        ),


User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Problem with transformations and container images synchi

#9 Post by xela »

*If you were talking about this btw, I cannot replicate your issue, there seems to be no delay or anything unexpected no matter how fast you change the variable:

Code: Select all

image Horse_Under:     # This combines the base horse body with the "Rider" dynamic image, which is customizable
    contains:
        Solid("#e5be01", xysize=(200, 200))
    contains:
        Solid("#aae03a", xysize=(150, 150))
        ypos -290
        xpos 180
    xpos -60
    ypos 120

image Horse_Over: # This is the head.
    contains:
        Solid("#31637d", xysize=(100, 100))    
    xpos -60
    ypos 120

image Horse_Under_1: #this is a basic movement cycle
    "Horse_Under"   
    ease 1.5 ypos 300 subpixel True    #50
    ease 1 ypos 120 subpixel True 
    repeat

image Horse_Over_1: #this is a basic movement cycle
    "Horse_Over" 
    ease 1.5 ypos 300 subpixel True   
    ease 1 ypos 120 subpixel True
    repeat
       

image Horse_Animation:  # this is the main image container for the horse and rider.
    contains:
        ConditionSwitch(  #this meant to show the static version if Speed is 0, and the animated version if it is 1.
            "Speed == 0", "Horse_Under", 
            "Speed == 1", "Horse_Under_1",
            "Speed != 0", "images/nothing.png",
            ),           
    contains:
        ConditionSwitch( 
            "Speed == 0", "Horse_Over", 
            "Speed == 1", "Horse_Over_1",
            "Speed != 0", "images/nothing.png",
            ),     
    contains:
        Solid("#fff8e5", xysize=(100, 100))
        zoom 1.80
        ypos -120
        xpos -475
       
label start:  #This label is called to set up the animation image and place it on the screen.
    $ Speed = 0
    show Horse_Animation:
        zoom .55
        xpos 475
        ypos 120       
    with dissolve
    while 1:
        $ Speed = not bool(Speed)
        pause
Like what we're doing? Support us at:
Image

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Problem with transformations and container images synchi

#10 Post by Onishion »

Yeah, I have no idea what the deal is. It doesn't usually occur the first time I shift speeds, only after several shifts back and forth, and then once it starts glitching, it keeps glitching until I restart the game. The workaround I'm using is to re-show the image every time the speed changes, but this is klugey. I also tried Nyaa's Live Container version, but it does not work, the bits inside won't move around.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Problem with transformations and container images synchi

#11 Post by xela »

Me neither but the codebit itself is not well written, there seems to be absolutely no reason what so ever for two separate images, movement instruction should be a transform and Transform/ATL statement should be used, there is absolutely nothing I can see that would prevent you from using code similar to this:

Code: Select all

image Horse:
    contains:
        Solid("#e5be01", xysize=(200, 200))
    contains:
        Solid("#aae03a", xysize=(150, 150))
    contains:
        Solid("#31637d", xysize=(100, 100))

transform my_move():
    subpixel True 
    ease 1.5 ypos 300
    ease 1 ypos 120
    repeat

image Horse_Animation:
    contains:
        ConditionSwitch(
            "Speed == 0", Transform("Horse", pos=(200, 300)),
            "Speed == 1", At("Horse", my_move()),
            "Speed != 0", "images/nothing.png",
            ),
    contains:
        Solid("#fff8e5", xysize=(100, 100))
        zoom 1.80
        pos (-100, -200)
       
label start:
    $ Speed = 0
    show Horse_Animation:
        zoom .55
        pos (475, 120)
    with dissolve
    while 1:
        $ Speed = not Speed
        pause
*It doesn't do the same thing but it holds the exact same structure. I cannot see what it is that you're gaining by all those image declarations. And even if you're using those images separately, there is still no reason for all of the declarations.

You need to play around with ATL a little bit more, you have too many positioning all over the place which can clearly be avoided and improved upon. People mentioned training in the other thread, try cutting your own code to the cleanest version of itself that you possibly can and see how much you can learn from that.
Like what we're doing? Support us at:
Image

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Problem with transformations and container images synchi

#12 Post by Onishion »

Me neither but the codebit itself is not well written, there seems to be absolutely no reason what so ever for two separate images, movement instruction should be a transform and Transform/ATL statement should be used, there is absolutely nothing I can see that would prevent you from using code similar to this:
Maybe not, I'll certainly give it a try. ;) I was using the tools that I understood, which I'm always aware are not likely the best possible tools. ;)

Thanks for the example though, I've learned a few efficiency changes from it. You know, when I first started coding the game, I would implement binary choices with "variable = '1' . . . variable = '0'", and then check them with "if variable == "1". . ." Since then I shifted those to "using 1 and 0 as integers to represent true and false, and "if variable/if not variable" to check them. I really do try to streamline as best I can.

Code: Select all

 while 1:
        $ Speed = not Speed
        pause
If you don't mind my asking, why do you use this bit above? What is it accomplishing? I don't believe I have anything like that in my code. I call my "animation start" label to place the full sequence in position, and then the "animation end" label (which I didn't show but it's mostly just the reverse) to put it all away. And btw, since you seem to understand all this stuff really well, do you know of a way to implement transitions or intermediate animations in between speed shifts? Like right now if it's animating and is not at the start position when I shift to static version, it just jumps there, rather than smoothly shifting there. I tried using "on show" and "on hide" type stuff, but it wouldn't work when what was changing was the condition switch.


Anyways, I'll try to implement a version of my code with your structure and see if it works how I need it to, I don't see why it wouldn't.

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Problem with transformations and container images synchi

#13 Post by trooper6 »

Onishion wrote: Thanks for the example though, I've learned a few efficiency changes from it. You know, when I first started coding the game, I would implement binary choices with "variable = '1' . . . variable = '0'", and then check them with "if variable == "1". . ." Since then I shifted those to "using 1 and 0 as integers to represent true and false, and "if variable/if not variable" to check them. I really do try to streamline as best I can.
Is there a reason you don't use booleans to check true and false?

Code: Select all

$ variable = True 
or

Code: Select all

$ variable = False
this way you can do:

Code: Select all

if variable:
    "blah blah"
or

Code: Select all

if not variable:
    "blah blah"
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Problem with transformations and container images synchi

#14 Post by Onishion »

Ok, I tested it out, seems to work pretty well so far. I was getting that synching issue again for some reason, but then I tweaked a few things and it seemed to fix itself. The tweaks I made were to change the following:

Code: Select all

image Horse:
    contains:
        Solid("#e5be01", xysize=(200, 200))
    #. . . etc.
#to
image Horse:
    contains:
        Solid("#e5be01", xysize=(200, 200))
    #. . . etc.
    pos (-60, 200)

#and in the final container,

"Speed == 0", Transform("Horse", pos=(200, 300)),
#to
"Speed == 0", Transform("Horse"),

#basically shifting where the default position is defined
Doing it the other way not only still had the synching issue, but also seemed to cause an issue where every time I closed and reopened the animation image part of it would jump slightly to the right of where it was meant to be and then start cycling again. It definitely is streamlined though and seems to work better, and I mostly understand it so I can apply the elements to other portions of the project, so thanks. ;)
Is there a reason you don't use booleans to check true and false?
I've noticed a lot of people do, and assume that's the "proper" practice. The thing is though, if I use:

Code: Select all

$ Variable = 1
#and
$ Variable = 0
Those work fine in the condition checks you posed. The integer 1 (or anything else really, but 1 is simple if I'm just doing a binary choice) seems to give the same results as True, and 0 gives the same results as "False" when used in "not Variable" checks. So, given that, I figure it's easier and less space taken up typing out a single digit than it is a 4-5 letter word, right? I suspect that it might somehow be less data efficient, but it's certainly less typing. ;) So why shouldn't I be doing that?

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Problem with transformations and container images synchi

#15 Post by xela »

Code: Select all

>>> True == 1
True
>>> False == 0
True
>>> int(True)
1
>>> int(False)
0
>>> not 0
True
>>> not 1
False
>>> 
They are interchangeable, 1/0 should work slightly faster if every nanosecond counts (*which is almost never), True/False should be used in project with multiple coders for readability and to avoid confusion. I didn't know that you wanted to reset the animation to it's original position on variable change so the:

Code: Select all

while 1:
    s = not s
just change the state of the displayable. Did you solve all other issues?
Like what we're doing? Support us at:
Image

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot], Majestic-12 [Bot]