I'm making a contraption to help with making sprites. It consists of:
- a "sprite" canvas, storing the picture for the sprite
- a "hitbox" canvas storing position and size of the sprite's hitbox
- a button to copy a part of the background of the card the contraption is on
- an invisible slider with internal function (keeps track of whether the interacting user is setting the top left corner or bottom right corner of the hitbox)
I'm running into the following issue: I copy the background of a card into an instance of my contraption and set the hitbox by dragging and/or clicking on the larger "sprite" canvas. After saving and quitting decker, upon re-opening the deck my sprite (the picture part) is still there, however the hitbox is reset to prototype value... Any idea why the size & pos of this second canvas does not persist? For reference here's the contraption:
{contraption:sprite_maker}
size:[140,140]
resizable:1
margin:[0,0,0,27]
description:"make a sprite"
script:"sprite_maker.0"
attributes:{"name":[],"label":[],"type":[]}
{widgets}
sprite:{"type":"canvas","size":[134,107],"pos":[4,4],"locked":1,"script":"sprite_maker.1","show":"transparent","image":"%%IMG2AIYAawD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8AOg==","scale":1}
hitbox:{"type":"canvas","size":[22,36],"pos":[57,32],"locked":1,"script":"sprite_maker.2","show":"transparent","draggable":1,"scale":1}
copy:{"type":"button","size":[109,20],"pos":[10,116],"script":"sprite_maker.3","text":"copy background"}
click_field:{"type":"slider","size":[100,25],"pos":[125,113],"show":"none","interval":[0,1]}
{script:sprite_maker.0}
me.show:"transparent"
on get_sprite do
sprite.copy[(0, 0) sprite.size]
end
on get_hitbox do
offset:hitbox.pos
size:hitbox.size
("offset", "size") dict (list offset), (list size)
end
{end}
{script:sprite_maker.1}
on click pos do
if click_num[] = 0
set_ul_corner[pos]
elseif click_num[] = 1
set_br_corner[pos]
end
end
on click_num do
click_field.value
end
on set_ul_corner pos do
offset_pos:me.pos+pos
hitbox.pos:offset_pos
click_field.value:1
end
on set_br_corner pos do
offset_pos:me.pos+pos
hb_pos:hitbox.pos
size:offset_pos-hb_pos
if size[0] < 0
hb_pos[0]:hb_pos[0]+size[0]
size[0]:-size[0]
end
if size[1] < 0
hb_pos[1]:hb_pos[1]+size[1]
size[1]:-size[1]
end
hitbox.pos:hb_pos
hitbox.size:size
click_field.value:0
end
on drag pos do
end
on release pos do
end
{end}
{script:sprite_maker.2}
on click pos do
end
on drag pos do
end
on release pos do
end
{end}
{script:sprite_maker.3}
current_card:deck.card
on click do
pos:sprite.offset
size:sprite.size
card_background:current_card.image
cropped:card_background.copy[pos size]
sprite.paste[cropped (0, 0)]
end
{end}
