Positioning Sprites

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
Bellrose980
Newbie
Posts: 2
Joined: Tue Jul 17, 2018 8:56 pm
Projects: Distinction
Contact:

Positioning Sprites

#1 Post by Bellrose980 »

Hi.
I'm trying to place two sprites on the screen. One on the left and one on the right. I tried using the "at left" and "at right" commands but they place the sprites both to high and in the centre. So instead I used this command to create my own positions:

Code: Select all

transform my_left:
    xalign -0.9 yalign -3
transform my_right:
    xalign ? yalign -3
The question mark in my_right is the spot where I can't find a value to place the sprite on the other side of the screen sitting at the same distance as my_left.
Thank You

User avatar
Per K Grok
Miko-Class Veteran
Posts: 882
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
itch: per-k-grok
Location: Sverige
Contact:

Re: Positioning Sprites

#2 Post by Per K Grok »

Bellrose980 wrote: Tue Jul 17, 2018 9:02 pm Hi.
I'm trying to place two sprites on the screen. One on the left and one on the right. I tried using the "at left" and "at right" commands but they place the sprites both to high and in the centre. So instead I used this command to create my own positions:

Code: Select all

transform my_left:
    xalign -0.9 yalign -3
transform my_right:
    xalign ? yalign -3
The question mark in my_right is the spot where I can't find a value to place the sprite on the other side of the screen sitting at the same distance as my_left.
Thank You
Ok.
Think of your image as a rectangle. What align (xalign/yalign) does is to align this rectangle with the rectangle of the game screen.
xalign 0.0 align the left side of the image rectangle with the left side of the game screen rectangle
xalign 1.0 align the right side of the image rectangle with the right side of the game screen rectangle
xalign 0.5 puts the image in the middle of the game screen rectangle in the x direction

To go left of the left side of the game screen rectangle you need a value below 0.0. You say you have used -0.9 which would put the left side of your image almost a game screen width to the left of the left side of the game screen. Is that really correct? For that image to show up in the game screen it would have to be as wide as the game screen.
To go right of the right side of the game screen rectangle you need a value higher than 1.0.


One thing you should observe is that the align command takes floats not integers. 1 (integer) is not the same thing as 1.0 (float) to a computer program.

yalign -3
does not really do anything
yalign -3.0
will place your image way above the game screen rectangle.

--------

You might also want to look at xpos/ypos which is a different way of positioning images, based of number of pixles from the game screen top left corner.

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: Positioning Sprites

#3 Post by Remix »

An image will, unless adjusted, be positioned based upon its top left corner.
For your case it would be nicer to use the centre pixel or maybe the one at the base in the middle, so we use anchors:

Code: Select all

transform my_left:
    anchor (0.5, 1.0) # 0.5 of the x direction (middle) 1.0 of the y (base)
    xalign 0.2 # place that pixel 0.2 of the screen x 
    yalign 1.0 # place that pixel at the base of the screen

transform my_right:
    anchor (0.5, 1.0) 
    xalign 0.8
    yalign 1.0
Frameworks & Scriptlets:

rames44
Veteran
Posts: 233
Joined: Sun May 29, 2016 4:38 pm
Contact:

Re: Positioning Sprites

#4 Post by rames44 »

@Remix - shouldn’t that be xpos/ypos instead of xalign/yalign in your example? “Align” will reset the anchors, no?

Post Reply

Who is online

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