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.
-
Exiscoming
- Regular
- Posts: 127
- Joined: Tue Apr 29, 2014 5:37 pm
-
Contact:
#1
Post
by Exiscoming » Thu Apr 30, 2020 5:59 pm
I'm trying to move an image via a button. Each time you press the button, the image xpos moves 100. Here's a simplified version:
Code: Select all
image bob = "bob.png" # Define an image for bob.
screen button: # Create a simple image button to make Bob move.
vbox xalign 0.1 yalign 0.1:
imagebutton:
idle "moveBt.png"
hover "moveBt-hover.png"
action Jump("move")
label start: # Start of the game
show bob:
xpos 150 ypos 150
call screen button
label move: # The label which is suppose to move the image
# Get bob's position and move him linear 1.0 plus 100 xpos.
What is the best way to get bob's current position and how do I add +100 xpos to it?
xpos or xalign both work, but I figured xpos might be easier.
-
hell_oh_world
- Miko-Class Veteran
- Posts: 777
- Joined: Fri Jul 12, 2019 5:21 am
- Projects: The Button Man
- Organization: NILA
- Github: hell-oh-world
- Location: Philippines
-
Contact:
#2
Post
by hell_oh_world » Fri May 01, 2020 12:54 am
Exiscoming wrote: ↑Thu Apr 30, 2020 5:59 pm
I'm trying to move an image via a button. Each time you press the button, the image xpos moves 100. Here's a simplified version:
Code: Select all
image bob = "bob.png" # Define an image for bob.
screen button: # Create a simple image button to make Bob move.
vbox xalign 0.1 yalign 0.1:
imagebutton:
idle "moveBt.png"
hover "moveBt-hover.png"
action Jump("move")
label start: # Start of the game
show bob:
xpos 150 ypos 150
call screen button
label move: # The label which is suppose to move the image
# Get bob's position and move him linear 1.0 plus 100 xpos.
What is the best way to get bob's current position and how do I add +100 xpos to it?
xpos or xalign both work, but I figured xpos might be easier.
i don't know if its possible inside the label, since once the statements get executed it won't rerun for changes that you make for positions and such, unless you rerun the statement or the label containing it so it would update, but you can do this inside screens.
Code: Select all
default my_pos = 150
screen bob:
add "bob":
xpos (my_pos) ypos 150
vbox xalign 0.1 yalign 0.1:
imagebutton:
idle "moveBt.png"
hover "moveBt-hover.png"
action [
SetVariable("my_pos", my_pos + 100),
If(
my_pos >= 500,
Jump("something")
)
]
label start:
call screen bob
-
Exiscoming
- Regular
- Posts: 127
- Joined: Tue Apr 29, 2014 5:37 pm
-
Contact:
#3
Post
by Exiscoming » Sat May 02, 2020 11:35 am
Hey hell_oh_world, thanks for the reply! I've been working on it and I think I figured it out.
So I didn't want to use a screen, because I wanted to animate the move. Instead I did the following.
Code: Select all
default moveSlots = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] # Make a list of 10 locations to move
default locationBob = 0 # Define your starting location
label moveForward:
###### See if the next spot is empty ######
$ canIMove = locationBob + 1 # Get current position + 1
if moveSlots[canIMove] == 0: # Is current position + 1 empty in the moveSlots list?
$ bobMove = renpy.get_image_bounds("bob") # Check the xpos location of image "bob"
$ bobMove = int(threeMove[0]) # Convert xpos you get, from FLOAT into INT
show bob:
linear 0.5 xpos (bobMove + 115) # Take current xpos and add +115 over half a second.
It took me some time to figure out, but I got there in the end.
Users browsing this forum: Bing [Bot], Google [Bot]