[solved / fixed] Drag & Drop Overlap and Snap Function

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
User avatar
m_from_space
Miko-Class Veteran
Posts: 974
Joined: Sun Feb 21, 2021 3:36 am
Contact:

[solved / fixed] Drag & Drop Overlap and Snap Function

#1 Post by m_from_space »

Hello,

I played around with the Drag & Drop feature of Ren'py.
https://www.renpy.org/dev-doc/html/drag_drop.html

Consider some kind of basketball situation with a (draggable) Drag called "drag_ball" that you can drag around, and there is also a (droppable) Drag called "drop_net" where you can drop the ball into.

Code: Select all

drag:
	child "ball" # the image of the ball
	drag_name "drag_ball"
	draggable True
	droppable False
	dragged obj_dragged
	
drag:
	child "net" # the image of the net
	drag_name "drop_net"
	draggable False
	droppable True

Now it is easy to just drop the ball into the net following the Ren'py documentation. And it is also possible to let the "ball" snap to the bottom of the screen - using the Drag.snap function - if it was not directly put into the net, I figured that one out.

Code: Select all

def obj_dragged(drags, drop):
	# the drag was not dropped onto a droppable drag
	if not drop:
		if drags[0].drag_name == "drag_ball":
			# let the ball snap to the bottom of the screen within 1.0 seconds
                	drags[0].snap(drags[0].x, 600, 1.0)
        # the drag was dropped onto a droppable drag
        else:
                if drop.drag_name == "drop_net":
                # we hit the net
                    return True
        return
But now I have some questions:

1) Is it possible to trigger that the ball overlaps the net while snapping to the bottom of the screen when the player did release it above the net? I actually want the ball to fall down and when it is overlapping the net, a function should trigger.

2) Is it possible to trigger when the Drag.snap() function ended its animation of 1 seconds before the script moves on? (This would be a workaround for question 1 if the ball is at a certain position.)

3) I really don't understand what the drop_allowable function is doing. Can you help me?

Thank you!

User avatar
m_from_space
Miko-Class Veteran
Posts: 974
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: [solved / fixed] Drag & Drop Overlap and Snap Function

#2 Post by m_from_space »

I solved this problem differently, so no need to answer here. :)

Post Reply

Who is online

Users browsing this forum: barsunduk, bloodzy, dragondatingsim, Majestic-12 [Bot]