Hey,
i have Version 1.2.151 of Defold and just started the tutorials series… I am stuck in the Astronaut Walking Tutorial at the end. The astronaut is moving but not animating at all. I checked the code a thousand times. If i comment msg.post("#sprite", "play_animation", {id = anim}) out i get the default idle animation again. But uncommenting it destroys the animation Something changed and the tutorial is old or did i make something wrong? Playing the animations in atlas by hand works…they are there. They have their ID… i can’t find the problem
i tried commenting that line out again and put it in INIT for testing like this
msg.post(“#sprite”, “play_animation”, { id = hash(“back”) })
that again works… so. is it possible that in update there is a problem, because the msg.post is called every frame and the animation starts endlessly again and again? but you would know that if you made that tutorial … :-/ hmm
local speed = 150
function init(self)
-- Add initialization code here
-- Remove this function if not needed
msg.post(".", "acquire_input_focus")
self.dir = vmath.vector3()
self.current_anim = nil
end
function update(self, dt)
-- Add update code here
-- Remove this function if not needed
if vmath.length_sqr(self.dir) > 1 then
self.dir = vmath.normalize(self.dir)
end
local p = go.get_position()
go.set_position(p + self.dir * speed * dt)
local anim = hash("idle")
if self.dir.x > 0 then
anim = hash("right")
elseif self.dir.x < 0 then
anim = hash("left")
elseif self.dir.y > 0 then
anim = hash("back")
elseif self.dir.y < 0 then
anim = hash("front")
end
if anim ~= self.current_anim then
--msg.post("#sprite", "play_animation", { id = anim })
self.current_aim = anim
end
self.dir = vmath.vector3()
end
function on_input(self, action_id, action)
-- Add input-handling code here
-- Remove this function if not needed
if action_id == hash("front") then
self.dir.y = -1
elseif action_id == hash("back") then
self.dir.y = 1
elseif action_id == hash("left") then
self.dir.x = -1
elseif action_id == hash("right") then
self.dir.x = 1
end
end