Defining Drag as displayable

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
Milkymalk
Miko-Class Veteran
Posts: 762
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

Defining Drag as displayable

#1 Post by Milkymalk »

The docs say that if I want to reference a Drag after creating it, I should create it as a displayable. So I did this:

Code: Select all

init:
    image bento_rice = "Bento/bento_rice.png"

init python:
    bento_ingredients["rice"] = Drag(d="bento_rice", droppable=False, dragged=bento_dragged)

screen test():
    fixed:
        xpos 100
        ypos 100
        xsize 1200
        ysize 800
        add Solid("#00a0a0")
        draggroup:
             add bento_ingredients["rice"]
And it works. However, the Drag is always placed at (0, 0) and I can't add any attributes without getting an error message, like as or at.

The use of this feature is completely undocumented and there are no examples. Can someone please explain to me how this works or give me example code that I can analyze?
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

philat
Eileen-Class Veteran
Posts: 1953
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Defining Drag as displayable

#2 Post by philat »

The following mostly seems to work. For reference, supplying transforms to a drag using at is not supported even when using screen drags (not Drag()s). Other attributes (like dragged, draggable, etc.) should probably be given in the Drag() definition and not added to the screen directly.

Code: Select all

screen dragdroptest():
    draggroup:

        add test_drag_displayable:
            as test_drag_as
        add test_drag_displayable_two:
            as test_drag_as_two

    vbox:
        textbutton "Test" action Function(test_drag_as.snap, 450, 150, 1.0)
        textbutton "Test2" action Function(test_drag_as_two.snap, 450, 400, 1.0)

init python:
    test_drag_displayable = Drag(Solid("#FFF6", xysize=(150,150)), xpos=200, ypos=300)
    test_drag_displayable_two = Drag(At(Solid("#FF06", xysize=(150,150)), alpha_dissolve), xpos=400, ypos=100)

init -1:
    transform alpha_dissolve:
        alpha 0.0
        linear 0.5 alpha 1.0

User avatar
Milkymalk
Miko-Class Veteran
Posts: 762
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

Re: Defining Drag as displayable

#3 Post by Milkymalk »

I didn't think of using a block for the as-attribute, thank you.

In your example, you either set the position in the Drag() declaration or with a button. How would I set the position when I create the drag? I want to use the Drag() as a template, but add it at a dynamic position without having to click a button.
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

philat
Eileen-Class Veteran
Posts: 1953
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Defining Drag as displayable

#4 Post by philat »

*shrug* tbh not sure, I don't tend to use Drags() much. That said, I haven't really found any reason to need Drags(), since you can always build the drags programmatically if you need to get data from elsewhere. For example:

Code: Select all

init python:
    def rice_dragged(drags, drop):
        print("rice")

    def eggs_dragged(drags, drop):
        print(drags[0].drag_name)

    bento_ingredients = {
        "rice": {
            "name" : "Rice",
            "image" : Solid("#FFF9", xysize=(100,100)),
            "draggable": False,
            "dragged": rice_dragged,
            "pos": (100, 100)
        },
        "eggs": {
            "name" : "Eggs",
            "image" : Solid("#F009", xysize=(100,100)),
            "draggable": True,
            "dragged": eggs_dragged,
            "pos": (500,500)
        }
    }

screen dragdroptest():
    draggroup:
        for k, v in bento_ingredients.items():
            drag:
                drag_name v["name"]
                child v["image"]
                draggable v["draggable"]
                dragged v["dragged"]
                xpos v["pos"][0]
                ypos v["pos"][1]

User avatar
Milkymalk
Miko-Class Veteran
Posts: 762
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

Re: Defining Drag as displayable

#5 Post by Milkymalk »

Hm, that would work, but defeats the point of being able to reference the Drag via an object name.
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

Post Reply

Who is online

Users browsing this forum: Bing [Bot]