Hello everybody. I have a question, I do not know if it is a silly doubt but I would like to solve it because I wanna sleep tonight :p
Ok, so... Here I go: is it possible to get the X and Y values of the position where a drag object has been drop? I want to save that information in a few variables but I can't find a way to do it.
On the other hand, is it possible to save in a variable the value of the width of the drag object?
Thank you all!
Drag&Drop: how to know coordenates of drop position?
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.
Re: Drag&Drop: how to know coordenates of drop position?
Except for d, all of the parameters are available as fields (with the same name) on the Drag object. In addition, after the drag has been rendered, the following fields become available:
x, y
The position of the Drag relative to its parent, in pixels.
w, h
The width and height of the Drag's child, in pixels.
https://www.renpy.org/doc/html/drag_drop.html
Re: Drag&Drop: how to know coordenates of drop position?
philat wrote: ↑Fri Oct 04, 2019 9:23 pmExcept for d, all of the parameters are available as fields (with the same name) on the Drag object. In addition, after the drag has been rendered, the following fields become available:
x, y
The position of the Drag relative to its parent, in pixels.
w, h
The width and height of the Drag's child, in pixels.
https://www.renpy.org/doc/html/drag_drop.html
Yes, I've read the documentation but I don't know how to do it. I'm a student and not a programmer, I don't have much idea and that's why I ask, to learn.
Re: Drag&Drop: how to know coordenates of drop position?
Yeah, I'm not a programmer either. You asked two questions. Can you access a Drag's x/y/width? If so, how do you store it in a variable? The documentation answers both. 1. Yes, a Drag's x/y/width are available properties. 2. There is literally an example of a Drag's properties being stored in a variable in the documentation.
After dragging, if a drop occurred, the variable detective now stores the drag's drag_name and the variable city now stores the drop's drag_name. drags[0].x would be the drag's x position.
If you have a question beyond what is in the documentation, you need to be more specific.
Code: Select all
init python:
def detective_dragged(drags, drop):
if not drop:
return
store.detective = drags[0].drag_name
store.city = drop.drag_name
return True
If you have a question beyond what is in the documentation, you need to be more specific.
Re: Drag&Drop: how to know coordenates of drop position?
Extending philat's answer, if you dragged and dropped the object somewhere onscreen (and not over droppable object), then you can store its coordinates like
Code: Select all
init python:
def detective_dragged(drags, drop):
if not drop:
store.my_x = drags[0].x
store.my_y = drags[0].y
Re: Drag&Drop: how to know coordenates of drop position?
Thank you, it works fine! My mistake was that I wrote "drop" instead of "drags[0]" >.<Alex wrote: ↑Sat Oct 05, 2019 5:37 amExtending philat's answer, if you dragged and dropped the object somewhere onscreen (and not over droppable object), then you can store its coordinates like(you might need to set the default values for my_x and my_y (as usually) to not get error)Code: Select all
init python: def detective_dragged(drags, drop): if not drop: store.my_x = drags[0].x store.my_y = drags[0].y
Another question regarding drag and drop: is it possible to limit the drag area? In other words... that the object can only be moved only on a area of the screen with drag limits.
Re: Drag&Drop: how to know coordenates of drop position?
Well, you need to place your draggroup inside a kind of container then, so it would be limited inside it and not inside the whole screen, like
Code: Select all
image red:
Solid("#c00")
size(200, 200)
image blue:
Solid("#00c")
size(200, 200)
screen test_drag_drop_area_scr():
frame:
pos (100, 100)
side "c b r":
area (0, 0, 600, 400)
viewport id "vp":
child_size (1200, 800)
draggable True
draggroup:
drag:
drag_name "red"
child "red"
droppable False
#dragged detective_dragged
xpos 100 ypos 100
drag:
drag_name "blue"
child "blue"
droppable False
#dragged detective_dragged
xpos 300 ypos 300
bar value XScrollValue("vp")
vbar value YScrollValue("vp")
# The game starts here.
label start:
"..."
show screen test_drag_drop_area_scr
"... ..."
"?!"
Who is online
Users browsing this forum: No registered users