A couple of questions about drag and drop

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.
Post Reply
Message
Author
Morok D
Regular
Posts: 25
Joined: Fri Mar 25, 2016 9:24 am
Contact:

A couple of questions about drag and drop

#1 Post by Morok D »

Help me find a solution, please:

1. Is it possible to make the desired function work right at the moment of "mouse down" on the drag object? In theory, the "activated" is responsible for this. But in fact, the function assigned to this is triggered only after I release the mouse button.

2. im.FactorScale (or im.Scale) zooms the image so that the result is displayed with the same coordinates of the upper left corner as the original image. If it is, for example, an object that must change its size when dragging it:

Code: Select all

drag:
    ...
    selected_hover_child im.Scale(pic, 100, 100)
    ...
then a large distance is obtained between the scaled object and the mouse cursor. Can I somehow make the image after zooming out to be displayed in the area of ​​the cursor?

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: A couple of questions about drag and drop

#2 Post by zmook »

The actual python code for Drags is in renpy/display/dragdrop.py -- I just tried reading it, and it looks like 'activated' is supposed to do what you want. I don't know if there's a bug or what. Could you post more of the code you're trying to use? Seems like this might take some debugging.
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

Morok D
Regular
Posts: 25
Joined: Fri Mar 25, 2016 9:24 am
Contact:

Re: A couple of questions about drag and drop

#3 Post by Morok D »

zmook wrote: Wed Dec 01, 2021 2:25 pm The actual python code for Drags is in renpy/display/dragdrop.py -- I just tried reading it, and it looks like 'activated' is supposed to do what you want. I don't know if there's a bug or what. Could you post more of the code you're trying to use? Seems like this might take some debugging.
Oh, you're right, thanks! The "activated" function works properly with

Code: Select all

renpy.restart_interaction()

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: A couple of questions about drag and drop

#4 Post by zmook »

Morok D wrote: Thu Dec 02, 2021 4:26 amOh, you're right, thanks! The "activated" function works properly with

Code: Select all

renpy.restart_interaction()
Ha! When in doubt, restart_interaction()...
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

Morok D
Regular
Posts: 25
Joined: Fri Mar 25, 2016 9:24 am
Contact:

Re: A couple of questions about drag and drop

#5 Post by Morok D »

I will clarify a little on the second question. There is a draggable object on the screen, for example, 400 by 400 pixels. After the player starts dragging it, it should be reduced to a size of 100 by 100. But at the same time, it should be in the area of ​​the mouse cursor. If I do it through:

Code: Select all

drag:
    ...
    selected_hover_child im.Scale(pic, 100, 100)
    ...
then if the player grabs the object by the lower right corner, the scaled-down object will be far away from the cursor. I even tried changing the coordinates of the object to the coordinates of the mouse cursor (via config.periodic_callbacks), but the result is infinite jumps of the object between its position and the position of the cursor while moving the mouse. :( Maybe there is some obvious (or not so obvious :D) way to avoid this problem? Another scaling method like?

Morok D
Regular
Posts: 25
Joined: Fri Mar 25, 2016 9:24 am
Contact:

Re: A couple of questions about drag and drop

#6 Post by Morok D »

Well, it seems like a good solution that works for me: change the grab_x and grab_y of the current dragged object to 0. In this case, after changing the scale of the object, it will move to the mouse cursor.

And one more question: if the dragged objects on the screen overlap each other (for example, apples are in the basket and partially overlap each other), and I need this behavior from them:

1. When I start to drag any object, it is in the position of the highest.
2. When I release the object and it returns to its place, it should take the position between the layers that it had before.

For example, if I start to drag the basket, then it becomes the topmost at the moment of the drag, but if I release it, it returns under the apples.

I think this can be done using the z parameter of the Drag class. But maybe there is some simpler and more obvious solution?

User avatar
Alex
Lemma-Class Veteran
Posts: 3094
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: A couple of questions about drag and drop

#7 Post by Alex »

Not tested, but try to set drag_raise property of draggable to False.

https://www.renpy.org/doc/html/drag_drop.html#Drag

Morok D
Regular
Posts: 25
Joined: Fri Mar 25, 2016 9:24 am
Contact:

Re: A couple of questions about drag and drop

#8 Post by Morok D »

Alex wrote: Thu Dec 09, 2021 3:16 pm Not tested, but try to set drag_raise property of draggable to False.

https://www.renpy.org/doc/html/drag_drop.html#Drag
Thanks, I tried on one of the first attempts. The problem then is that at the moment of dragging, the object from the "middle layers" does not become the topmost, it moves under the highest objects(

Post Reply

Who is online

Users browsing this forum: Google [Bot]