Question on how ypos and yalign works on sprite animations

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
Heiden
Regular
Posts: 140
Joined: Sat May 11, 2013 3:20 pm
Completed: Elvine, The Life Threads, Helena's Flowers, Dr. Frank's Build-A-Boyfriend, Beyond the Deep, The Bog's Heart, The Girl With the Gray Hair Awakens, The Far Rings, NB107A
Projects: The Town Pages, Kill the Prince?! [Nano 2020]
Tumblr: heidengames
itch: Heiden
Contact:

Question on how ypos and yalign works on sprite animations

#1 Post by Heiden »

Hi! I'm sorry if this has been asked before but I'm having a bit of an issue understanding how ypos and yalign works and I was hoping that someone could help me understand this issue.

Specifically, I have 2 character sprites (different characters) that I am trying to make appear with a little bit of an up/down movement. Character A's sprite is 455 x 575 while Character B's sprite is 455 x 600. My VN has a resolution of 800 x 600 (Yes I am working in the stoneages haha :'D).

Here's my code for their animations:

Code: Select all

transform centersadbobalign:
    xalign 0.5
    yalign 0.0
    linear 0.3 yalign 0.5
    linear 0.2 yalign 1.0
Which works great for Character A, but doesnt do anything for Character B.
However, changing the code to:

Code: Select all

transform centersadbobpos:
    xalign 0.5
    ypos 0
    linear 0.3 ypos 300
    linear 0.2 ypos 600
And now this animation works for both Character A and Character B.
I also noticed that adding a zoom for the transform centersadbobalign allows the transform to work on Character B's sprite.

Im assuming that the issue is that Character B's sprite is the same height as the game window, since it's fixed if I zoom in/out, but I dont understand why? Why is it that if I change it to ypos (moving the same amount of pixels I would in the other transform) it works, but yalign doesnt?

(I'm also using Renpy 6.99.6.727)
Completed: Elvine (GxB), The Life Threads, Helena's Flowers (GxG)(As Writer, Coder), Dr. Frank's Build-A-Boyfriend (BxB), Beyond the Deep (GxB)(As Artist), The Bog's Heart, The Girl with the Gray Hair Awakens, The Far Rings, NB107A.

All available to play on my itch.io page!

philat
Eileen-Class Veteran
Posts: 1909
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Question on how ypos and yalign works on sprite animatio

#2 Post by philat »

Align is equivalent to setting anchor and pos to the same value. Therefore, if the sprite is the same size as the screen, changing the sprite's align won't move it at all.

User avatar
Heiden
Regular
Posts: 140
Joined: Sat May 11, 2013 3:20 pm
Completed: Elvine, The Life Threads, Helena's Flowers, Dr. Frank's Build-A-Boyfriend, Beyond the Deep, The Bog's Heart, The Girl With the Gray Hair Awakens, The Far Rings, NB107A
Projects: The Town Pages, Kill the Prince?! [Nano 2020]
Tumblr: heidengames
itch: Heiden
Contact:

Re: Question on how ypos and yalign works on sprite animatio

#3 Post by Heiden »

Aha, oh gosh maybe I don't know enough programming to really understand the "why".

Well thank you so much for your help! I think I'll just use ypos in the future.
Completed: Elvine (GxB), The Life Threads, Helena's Flowers (GxG)(As Writer, Coder), Dr. Frank's Build-A-Boyfriend (BxB), Beyond the Deep (GxB)(As Artist), The Bog's Heart, The Girl with the Gray Hair Awakens, The Far Rings, NB107A.

All available to play on my itch.io page!

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

Re: Question on how ypos and yalign works on sprite animatio

#4 Post by Onishion »

I've been playing with this myself, and I'm just starting to truly understand it. Basically, each image has an "anchor," which is the point used to determine where it is. This defaults to 0,0, which is the top left corner of the image file, and 1.0,1.0 would be the bottom right corner. 0.5,0.5 is the center of the image. Changing pos will move that center point around, and it also defaults to 0,0 so if you just display a default image, it's top-left corner will appear in the top left corner of the screen. If you just display an image with a .5,.5 anchor, then it will show the bottom right quarter of the image in the top left corner of the screen. ;) Make sense? There is also "offset," which causes the image to shift some distance away from the "pos" you have it set at. This si sometimes useful when you want to pic an image to a "pos," but then have it move around while still being able to remember where it came from by resetting the offset to 0.

Any of these can be set with either pos (#,#), or xpos #, or ypos #. pos(235,400) is the same thing as xpos 235 ypos 400, and you can use them interchangeably. The number can either be an integer, like 235, which will put it exactly 235 pixels away from the anchor, or it can be a floating point, with a decimal point in there, where 0.0 is the top left corner of the object/space, 1.0 the bottom right, and anything else is relative to that

Align is used in a lot of examples, but can get kind of messy if you're making animations. That sets both the anchor point and the pos at the same time, so xalign .25 sets both the anchor point of that image to a point 1/4 from the left, but also sets the position of that anchor on the screen to 1/4 from the side of the screen. you can also use "center," which does the same, only sets the anchor to 50% of the image size. I hope that helped make sense of it all.

User avatar
Heiden
Regular
Posts: 140
Joined: Sat May 11, 2013 3:20 pm
Completed: Elvine, The Life Threads, Helena's Flowers, Dr. Frank's Build-A-Boyfriend, Beyond the Deep, The Bog's Heart, The Girl With the Gray Hair Awakens, The Far Rings, NB107A
Projects: The Town Pages, Kill the Prince?! [Nano 2020]
Tumblr: heidengames
itch: Heiden
Contact:

Re: Question on how ypos and yalign works on sprite animatio

#5 Post by Heiden »

OOOHHHHHHHHHHHHH, omg now I understand. THANK YOU!!!!!!

In case anyone is reading this with the same problem and still doesn't really know why this is happening-

So in the case of my image, setting yalign to 0 tells the game to put the top of my sprite at the top of the bg image, which it already is since it's the same height. Then yalign at 0.5 takes the midpoint of my sprite (sets the anchor at the midpoint) and sets it to the midpoint of the bg image, which is already there because it's the same height. And then yalign at 1.0 takes the bottom of my sprite and sets it to the bottom of my bg image, which is already there because it is, once again, the same height!

Thank you so so much for your help!
Completed: Elvine (GxB), The Life Threads, Helena's Flowers (GxG)(As Writer, Coder), Dr. Frank's Build-A-Boyfriend (BxB), Beyond the Deep (GxB)(As Artist), The Bog's Heart, The Girl with the Gray Hair Awakens, The Far Rings, NB107A.

All available to play on my itch.io page!

Post Reply

Who is online

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