Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(+1)

im having a tad difficult time understanding contraptions.. can they be draggable?

my contraption in question is just made of one canvas; the canvas itself is draggable but (naturally) it doesnt move the rest of the contraption with it. what is a good approach to this?

(3 edits) (+2)

You can. This is how I’ve done it:

%%WGT0{"w":[{"name":"cammy1","type":"contraption","size":[100,30],"pos":[125,36],"def":"cammy","widgets":{"cammy_edit":{},"drag_handle":{},"resize_handle":{},"offset":{}}}],"d":{"cammy":{"name":"cammy","size":[100,30],"resizable":1,"margin":[16,15,16,15],"widgets":{"cammy_edit":{"type":"field","size":[70,30],"pos":[15,0],"script":"on change val do\n  if (\"\\n\" in val)\n    val: \"\" fuse on _ x do if (x~\"\\n\") \"\" else x end end @ val\n    show[val]\n    p: (list \"%v%s %n\") parse val\n    show[p]\n    t: p[0]\n    n: p[2]\n    valid: 0\n    if (\"field\" in t) |\n       (\"canvas\" in t) |\n       (\"slider\" in t) |\n       (\"button\" in t) |\n       (\"grid\" in t)    \n      w: card.parent.add[t]\n      w.pos: card.pos\n      w.size: card.size\n      valid: 1\n    else\n      w: card.parent.add[\"contraption\" t]\n      if !(w~nil)\n        w.pos: card.pos\n        w.size: card.size\n        valid: 1\n      end\n    end\n    \n    if valid\n      p: (list \"%v%s %j%s %n\") parse (n drop val)\n      k: p[0]\n      v: p[2]\n      n: n + p[4]\n      while !((k~nil) | (v~nil))\n        w[k]: v\n        p: (list \"%v%s %j%s %n\") parse (n drop val)\n        k: p[0]\n        v: p[2]\n        n: n + p[4]\n        show[p]\n      end\n      card.parent.remove[card]\n    end\n  end\nend"},"drag_handle":{"type":"canvas","size":[14,14],"pos":[0,0],"script":"on click pos do\n  rel_pointer: pointer.pos - card.pos\n  offset.text: (\"%J\" format (list (me.pos - rel_pointer)))   \n  cammy_edit.locked: 1\n  resize_handle.draggable: 0\nend\n\non drag pos do\n  card.pos: pointer.pos + (list (\"%J\" parse offset.text))\n  me.pos: (0,0)\n  cammy_edit.locked: 1\n  resize_handle.locked: 0\nend\n\non release pos do\n  card.pos: pointer.pos + (list (\"%J\" parse offset.text))\n  me.pos: (0,0)\n  cammy_edit.locked: 0\n  resize_handle.draggable: 1\nend","draggable":1,"scale":1},"resize_handle":{"type":"canvas","size":[14,14],"pos":[86,16],"script":"on click pos do\n  rel_pointer: pointer.pos - card.pos\n  offset.text: (\"%J\" format (list (me.pos - rel_pointer)))\n  cammy_edit.locked: 1\n  drag_handle.draggable: 0\nend\n\non drag pos do\n  offset: (list (\"%J\" parse offset.text))\n  rel_pointer: pointer.pos - card.pos\n  me.pos: rel_pointer + offset\n  card.size: me.pos + me.size\n  cammy_edit.size: me.pos + (-16,14)\n  cammy_edit.locked: 1\n  drag_handle.draggable: 0\nend\n\non release pos do\n  offset: (list (\"%J\" parse offset.text))\n  rel_pointer: pointer.pos - card.pos\n  me.pos: rel_pointer + offset\n  card.size: me.pos + me.size\n  cammy_edit.size: me.pos + (-16,14)\n  cammy_edit.locked: 0\n  drag_handle.draggable: 1\nend","draggable":1,"scale":1},"offset":{"type":"field","size":[40,14],"pos":[-50,-20],"value":"[-4,-5]"}}}}}

It does it by making canvases in the widget draggable and then updating the contraption it belongs to. It’s not particularly intuitive, which is why I copied the whole contraption so you can copy from it or modify it.

There might be better ways of doing it. I haven’t revisited that code in a while and it was one of the first contraptions I made when learning Decker and Lil.


Though, if the contraption is just composed of one widget, a canvas, does it need to be a contraption? Can you put the code in the canvas’s script, instead? Then, you could copy that canvas around if it needs to be replicated.