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.
-
frytkosz-555
- Newbie
- Posts: 11
- Joined: Mon May 31, 2021 12:09 pm
-
Contact:
#1
Post
by frytkosz-555 » Tue Jun 15, 2021 7:39 pm
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:

-
emz911
- Regular
- Posts: 103
- Joined: Fri Jun 23, 2017 2:23 pm
-
Contact:
#2
Post
by emz911 » Tue Jun 15, 2021 9:11 pm
Easiest way is to define one or two variables, for example:
Code: Select all
default myXpos = 0
default myYpos = 0
label wherever:
$ myXpos = 0.6
$ myYpos = 0.2
Then in the screen replace the numbers with the variable names:
Code: Select all
imagebutton:
xpos myXpos
ypos myYpos
-
HEXdidnt
- Regular
- Posts: 61
- 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:
#3
Post
by HEXdidnt » Wed Jun 16, 2021 5:16 am
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.
Code: Select all
transform randomplacement:
xpos renpy.random.random() ypos renpy.random.random()
or
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])
Could a similar approach work here? As in:
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")
*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?
As ever, dropping litter in the zen garden of your mind...

Users browsing this forum: No registered users