Page 1 of 1

Positioning Sprites

Posted: Tue Jul 17, 2018 9:02 pm
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

Re: Positioning Sprites

Posted: Wed Jul 18, 2018 4:07 am
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.

Re: Positioning Sprites

Posted: Wed Jul 18, 2018 4:58 am
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

Re: Positioning Sprites

Posted: Wed Jul 18, 2018 12:02 pm
by rames44
@Remix - shouldn’t that be xpos/ypos instead of xalign/yalign in your example? “Align” will reset the anchors, no?