Page 1 of 1
Defining Drag as displayable
Posted: Sun Apr 28, 2024 3:40 pm
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?
Re: Defining Drag as displayable
Posted: Sun Apr 28, 2024 10:34 pm
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
Re: Defining Drag as displayable
Posted: Mon Apr 29, 2024 4:40 am
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.
Re: Defining Drag as displayable
Posted: Mon Apr 29, 2024 8:05 am
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]
Re: Defining Drag as displayable
Posted: Tue Apr 30, 2024 10:49 am
by Milkymalk
Hm, that would work, but defeats the point of being able to reference the Drag via an object name.