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.
-
Nanahs
- Veteran
- Posts: 310
- Joined: Wed Aug 22, 2018 5:50 pm
-
Contact:
#1
Post
by Nanahs » Sat Oct 31, 2020 9:58 pm
There's a part in my game where I want the player to be able to place the decoration wherever they want.
Something like:
I'm using this very simple code:
Code: Select all
screen drag:
zorder 50
draggroup:
drag:
drag_name "plant"
draggable True
xpos -60 ypos 10
add "plant.png"
label start:
scene b
call screen drag
The thing is: I want the object to stay in the positon to where the person dragged it to. Is it possible?
Whenever I call this screen again, the object would be where the person put it.
Thank you so much.
-
_ticlock_
- Veteran
- Posts: 391
- Joined: Mon Oct 26, 2020 5:41 pm
-
Contact:
#2
Post
by _ticlock_ » Sat Oct 31, 2020 10:58 pm
Hi Nanahs,
You can find some nice examples for drag and drop: Check this links:
viewtopic.php?t=12504
viewtopic.php?t=16151
If you want to move it from one place to another (not dropping to particular drop), try this:
Code: Select all
init python:
def plant_dragged(drags, drop):
if not drop:
store.plant_pos[drags[0].drag_name][0] = drags[0].x
store.plant_pos[drags[0].drag_name][1] = drags[0].y
return
return True
screen drag:
zorder 50
draggroup:
drag:
drag_name "plant"
child "plant.png"
droppable False
dragged plant_dragged
xpos plant_pos["plant"][0] ypos plant_pos["plant"][1]
label start:
python:
plant_pos = {
"plant": (100,100) # Initial position for drag_name "plant"
}
scene b
call screen drag
-
_ticlock_
- Veteran
- Posts: 391
- Joined: Mon Oct 26, 2020 5:41 pm
-
Contact:
#3
Post
by _ticlock_ » Sat Oct 31, 2020 11:06 pm
I did a mistake: you need to change tuple (100,100) to list [100,100] :
Code: Select all
label start:
python:
plant_pos = {
"plant": [100,100] # Initial position for drag_name "plant"
}
-
Nanahs
- Veteran
- Posts: 310
- Joined: Wed Aug 22, 2018 5:50 pm
-
Contact:
#4
Post
by Nanahs » Wed Nov 11, 2020 9:46 am
_ticlock_ wrote: ↑Sat Oct 31, 2020 11:06 pm
I did a mistake: you need to change tuple (100,100) to list [100,100] :
Code: Select all
label start:
python:
plant_pos = {
"plant": [100,100] # Initial position for drag_name "plant"
}
Thank you so much! I'll try that
