Can't get Drag-drop dragging action?

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
newbiemate
Regular
Posts: 85
Joined: Tue Dec 19, 2017 1:36 pm
Contact:

Can't get Drag-drop dragging action?

#1 Post by newbiemate »

If you think back to diablo 3, if you drag a sword from the inventory screen, it'll highlight slots where you can drop the item into to equip the sword on your character. This visually prevents the player from dropping the item onto the character's foot, because the character's foot cannot equip a sword. Only their hands can, so that's why the slots on their hands are highlighted.

This is a nice UX, and I'm trying to build the same thing using renpy. I've been playing with Drag and Drop (https://www.renpy.org/doc/html/drag_drop.html), and the drag-drop mechanism works pretty well. However, the issue is I don't know how to 'highlight' the slots while the displayable is being dragged.

In this test snippet:

Code: Select all

init python:
    def do_dragged(drags, drop):
        if not drop:
            return
        return True

screen slot_idle():
    add "images/slot_idle.png" xpos 100 ypos 100
    
screen slot_highlight():
    add "images/slot_highlight.png" xpos 100 ypos 100

screen begin():
    draggroup:
        drag:
            drag_name "sword"
            child "images/sword.png"
            droppable True
            dragged do_dragged
            xpos 500
            ypos 500

label start:
    show screen slot_idle()
    call screen begin()
    return
The function do_dragged() seems to only run when the displayable is dropped, not while it's being dragged. How can I hide the slot_idle screen and show the slot_hightlight screen while I am dragging the displayable? And then vice-versa when the displayable has been dropped (ie, change back to idle instead of highlight)?

Post Reply

Who is online

Users browsing this forum: No registered users