Astronaut Walking Tutorial not Animating (SOLVED)

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 :frowning: 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 :frowning:


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

1 Like

Can you share your code here?

1 Like

it’s from the tutorial :frowning:

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
1 Like

You’ve made a small typo here

It should be

self.current_anim = anim

I think this will fix it :slight_smile:

5 Likes

wow, thats a little embarrassing :smiley: need more coffee :smiley: thank you very much.

3 Likes

No problem! Happy to help! :smiley:

3 Likes

Great job supporting on the forum @amel!

3 Likes

Thanks! I love this great community! Thank you Defold team for your hard work and dedication! It’s highly appreciated! :smile: :defold:

3 Likes