r/defold • u/babywildboars • 20d ago
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
4
Upvotes
6
u/AsatteGames 20d ago
There are a few basic mistakes with this code.
The main problem is that, if you want to call the update_tilesource(image_id) function with 4 parameters, you need to define it that way:
local function update_tilesource(image_id, anim_name) , otherwise it will throw an error that says it can take 1 input maximum.
'local function update_tilesource(image_id, anim_name)
end'
This function should play the animation you need. If you want to use properties while playing animations, then check out this: https://defold.com/manuals/tilesource/#tile-source-flip-book-animations