How to use spritesets in defold?

How do I animate a character when all of its movements are on a single image?

I would suggest you take a look at tile source in this case; you can then set start and end tile per animation group.

2 Likes



Excuse me I use animation but it doesn’t play the animation while moving it plays the animation when it’s idle What’s wrong with it please?

if action_id == hash("up") then
	position.y = position.y + 1
	if action.pressed then
		sprite.play_flipbook("#player", "up", function() os.exit() end)
	elseif action.released then
		sprite.play_flipbook("#player", "idle-up", function() os.exit() end)
	end

I’m using this judgment for playback now and it works but it’s not elegant, is there another way?

That is the way to control the logic.

One way to generalize is a step further, is to collect the input, and store it in a variable, and use it in the update loop (i.e. after all inputs are received)

E.g.

function init(self)
    self.input = vmath.vector3(0,0,0)
end

function update(self, dt)
    if self.input.x == 1;
        ...
    elseif self.input.x == -1;
        ...
    elseif self.input.y == 1;
        ...
    elseif self.input.y == -1;
        ...
    end
    self.input = vmath.vector3(0,0,0)
end

function on_input(self, action_id, action)
    if action.pressed then
        if action_id == hash("up") then
            self.input.y = self.input.y + 1
        elseif action_id == hash("down") then
            self.input.y = self.input.y - 1
        elseif action_id == hash("left") then
            self.input.y = self.input.x - 1
        elseif action_id == hash("right") then
            self.input.y = self.input.x + 1
        end
    end
end

thx