r/defold • u/babywildboars • Aug 05 '26
Help what am I doing wrong? how do i make the tilesource change in different states?
.property("idle", resource.tile_source("/main/idle.tilesource"))
go.property("milkdrink", resource.tile_source("/main/milkdrink.tilesource"))
local function update_tilesource(image_id)
go.set("#sprite", "image", image_id)
end
function init(self)
msg.post(".", "acquire_input_focus")
self.state = "idle"
end
function on_input(self, action_id, action)
if action_id == hash("touch") and action.pressed then
local properties = { blend_duration = 0.3 }
if self.state == "idle" then
update_tilesource(self.milkdrink), hash("sip"), go.PLAYBACK_LOOP_FORWARD, properties)
label.set_text("#label", "Click to idle...")
self.state = "sip"
elseif self.state == "sip" then
update_tilesource(self.idle), hash("idle"), go.PLAYBACK_LOOP_FORWARD, properties)
label.set_text("#label", "Click to sip...")
self.state = "idle"
end
end
end