How do I make an imagebutton appear in random positions like the x and yalign values being randomised, how do I do that?
Heres the code:
Imagebutton appearing in random positions on screen
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.
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.
-
- Newbie
- Posts: 11
- Joined: Mon May 31, 2021 12:09 pm
- Contact:
Re: Imagebutton appearing in random positions on screen
Easiest way is to define one or two variables, for example:
Then in the screen replace the numbers with the variable names:
Code: Select all
default myXpos = 0
default myYpos = 0
label wherever:
$ myXpos = 0.6
$ myYpos = 0.2
Code: Select all
imagebutton:
xpos myXpos
ypos myYpos
- HEXdidnt
- Regular
- Posts: 63
- Joined: Tue Aug 11, 2020 1:25 pm
- Projects: A Night at the Office, Embracing Christmas, The Masquerade Benefit
- Deviantart: HEXdidnt
- Location: Harrow, London, UK
- Contact:
Re: Imagebutton appearing in random positions on screen
Out of curiosity, and since I know it's possible to randomise the position of a displayable quite easily, just by using renpy.random, eg.
or
Could a similar approach work here? As in:
*though I'm guessing 1920 and 1080 would need to be replaced with the relevant pixel size minus half the button's size with xanchor and yanchor being set to 0.5 each?
Code: Select all
transform randomplacement:
xpos renpy.random.random() ypos renpy.random.random()
Code: Select all
transform randomplacement:
xpos renpy.random.randint(0,[max pixel width of screen minus width of image]) ypos renpy.random.randint(0,[max pixel height of screen minus height of image and text window])
Code: Select all
screen random_resources:
imagebutton:
xanchor 0.5
yanchor 0.5
xpos renpy.random.randint(0,1920)
ypos renpy.random.randint(0,1080)
idle "resource_placeholder1"
hover "resource_placeholder1hover"
action Jump ("metal_gain")
Who is online
Users browsing this forum: Alex, Majestic-12 [Bot]