Positioning Sprites: Custom Positions

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
harajukulolita
Regular
Posts: 75
Joined: Mon Jul 15, 2013 11:24 am
Completed: None so far!
Projects: Currently working on... Starlight Wishes
Tumblr: loli-studio
Deviantart: harajukulolita
Contact:

Positioning Sprites: Custom Positions

#1 Post by harajukulolita »

Hello to anyone reading :D I've looked up this topic quite a bit before and seen some examples although I'm not really completely satisfied with what I've seen. I've learnt to come to come to grips with the xpos and all those small details but what I want to know is:
1. Can I define custom positions once and apply them to all the sprites?

If for example say these are the positions I want to apply for left and right globally meaning for any sprite I use in the game (these are not really the positions :lol: )

Code: Select all

    $ left = Position(xpos= 0.35, xanchor='left')
    $ right = Position(xpos= 0.70, xanchor='right')
then how do I go about this?

And can I also see examples of scripts with these types of properties applied? The examples I've seen only show the bits of code to put into the script and I understand those but what I need to see is where to put these bits of code and how it looks overall. This would help loads :D *smoke screen: ninja stealth level 10* 8)

Tsapas
Regular
Posts: 69
Joined: Mon Oct 14, 2013 8:18 am
Contact:

Re: Positioning Sprites: Custom Positions

#2 Post by Tsapas »

Sure you can define your own, like this.

Code: Select all

init:
    $ screen_center = Position(xpos=0.5, ypos=0.5)

label start:
    show image at screen_center with dissolve
The above will place the image in the center of the screen and show it with a dissolve transition.

User avatar
harajukulolita
Regular
Posts: 75
Joined: Mon Jul 15, 2013 11:24 am
Completed: None so far!
Projects: Currently working on... Starlight Wishes
Tumblr: loli-studio
Deviantart: harajukulolita
Contact:

Re: Positioning Sprites: Custom Positions

#3 Post by harajukulolita »

Thank you loads for the help, now I understand where to place the code, I tried and it worked perfectly. Thank you :mrgreen:

User avatar
xavimat
Eileen-Class Veteran
Posts: 1460
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love, unknown
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Contact:

Re: Positioning Sprites: Custom Positions

#4 Post by xavimat »

You can also use the "transform" (it does the same than Tsapas' code)

Code: Select all

transform my_left:
    xalign .1 yalign 1.0
transform my_right:
    xalign .9 yalign 1.0
You can put this code wherever in a .rpy file, Ren'Py understands the "transform" as an "init" thing to do, even if you don't put the "init" word.
The "transform" accepts all the ATL language, you can use them to make animations too.

Later, in the game, you use the "at" statement, as Tsapas has showed:

Code: Select all

show my_image at my_left with easeinleft
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

User avatar
harajukulolita
Regular
Posts: 75
Joined: Mon Jul 15, 2013 11:24 am
Completed: None so far!
Projects: Currently working on... Starlight Wishes
Tumblr: loli-studio
Deviantart: harajukulolita
Contact:

Re: Positioning Sprites: Custom Positions

#5 Post by harajukulolita »

xavimat wrote:You can also use the "transform" (it does the same than Tsapas' code)

Code: Select all

transform my_left:
    xalign .1 yalign 1.0
transform my_right:
    xalign .9 yalign 1.0
You can put this code wherever in a .rpy file, Ren'Py understands the "transform" as an "init" thing to do, even if you don't put the "init" word.
The "transform" accepts all the ATL language, you can use them to make animations too.

Later, in the game, you use the "at" statement, as Tsapas has showed:

Code: Select all

show my_image at my_left with easeinleft
Thank you for the suggestion, that also seems like a good way to do it :)

User avatar
DrGonzo
Regular
Posts: 46
Joined: Fri Feb 23, 2018 9:12 pm
Location: Los Angeles, California
Contact:

Re: Positioning Sprites: Custom Positions

#6 Post by DrGonzo »

Hi,
I was using the code provided here and it worked great. Yesterday.

Today, it doesn't and I can't figure out why. Haven't made major changes to my code that would explain why this no longer works.

In script.rpy:

Code: Select all

init:    
    $ my_left = Position(xpos=0.1, ypos=1)
Then showing the image with:

Code: Select all

show side pov neutral at my_left
When I replace "my_left" with just "left" it works fine. But since I'd rather move it a bit more towards the center instead..

Any thoughts on why this code worked fine yesterday but not today?

Thanks!
Google search: "renpy thisismyquestion -org"
This gives you everything - except renpy.org results. Which I find useless 90% of the time.

User avatar
mitoky
Veteran
Posts: 316
Joined: Sat Feb 07, 2015 9:12 pm
Projects: The Purring Demon's Love, circus eterie
Contact:

Re: Positioning Sprites: Custom Positions

#7 Post by mitoky »

DrGonzo wrote: Sat Aug 11, 2018 5:11 pm Hi,
I was using the code provided here and it worked great. Yesterday.

Today, it doesn't and I can't figure out why. Haven't made major changes to my code that would explain why this no longer works.

In script.rpy:

Code: Select all

init:    
    $ my_left = Position(xpos=0.1, ypos=1)
Then showing the image with:

Code: Select all

show side pov neutral at my_left
When I replace "my_left" with just "left" it works fine. But since I'd rather move it a bit more towards the center instead..

Any thoughts on why this code worked fine yesterday but not today?

Thanks!
Add anchor to the code to have the exact point on the image, otherwise its taking the left side as overlapping point:

Code: Select all

init:    
    $ my_left = Position(xpos=0.1, ypos=1.0, xanchor=0.5, yanchor=1.0)

User avatar
DrGonzo
Regular
Posts: 46
Joined: Fri Feb 23, 2018 9:12 pm
Location: Los Angeles, California
Contact:

Re: Positioning Sprites: Custom Positions

#8 Post by DrGonzo »

Thank you for your suggestion, but this did not make a difference.
The image is still not being displayed, unless I use the predefined "at left" location.
Really strange, since it worked fine the day before.
Google search: "renpy thisismyquestion -org"
This gives you everything - except renpy.org results. Which I find useless 90% of the time.

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

#9 Post by trooper6 »

at left is working because "left" is a pre-defined transform, so it is working. You are getting problems with your code because you are using super old code.

Try the more modern ATL code:

Code: Select all

transform my_left:
    xalign 0.1
    yalign 1.0
    
label start:
    show character1 at my_left
    "This should work."
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

User avatar
DrGonzo
Regular
Posts: 46
Joined: Fri Feb 23, 2018 9:12 pm
Location: Los Angeles, California
Contact:

Re: Positioning Sprites: Custom Positions

#10 Post by DrGonzo »

@trooper6

Thanks, I had already tried that as well.
There is something else going on. I just changed all instances from "my_left" to "more_centered" - - and it started
working again.. Go figure.

I think it has to do with how RenPy remembers the show at position, so you don't have to constantly specify "at left" every time.
At least that is my understanding.
I'll just pad my side images to move them more towards the center.

Thanks for your input everyone!
Google search: "renpy thisismyquestion -org"
This gives you everything - except renpy.org results. Which I find useless 90% of the time.

Post Reply

Who is online

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