Cutting up a sprite from the atlas



As far as I can tell, sprites are packed into atlas, and when you load them into the GOs, the #sprite gets the size and location of the correct image from the atlas.

I’d like to know if it’s possible to slice up an image (into, say 10 horizontal strips) and then get 10 #sprites to display one strip each (and do this within defold, rather than in photoshop or whatever).

Then, I could use go.animate to do something like this (not exactly this, but something similar) using go.animate:

Any help? Bonus points if I don’t have to learn about rendering or shaders!



Not exactly what you asked but you could use a tilesource and chop up the text into 10 tiles like this:

You would have to set 10 animations for the tilesource denoting each slice. You could then assign each animation to a go/sprite.



You absolute genius!!! thank you ben james. I am, once again, awed by how powerful defold is and how useful the community can be. Now i just have to figure out how to animate it…



it only took me 30 minutes to get this far. That’s great. I am going to have to study exactly how that animation works and see how i can replicate it. It’s just scale.x, and position.x, right?? how hard can it be?!?!



Okay, how do you say this in lua?

Please can you set the x.position of every object in this table according to the size and scale of every object preceding it

I am particularly interested in doing this as efficiently as possible. The table has 16 elements and i don’t want to have a loop within a loop as it’s going in the update function… but i have a feeling the only way is going to be with an ipairs and within that, a “for i = k,0,-1 do”. Is that bad?



It’s not going to be bad unless you have many items.

Couldn’t you have an X offset variable that you increment for every item you place?



you are right dude. I already know how much the x value is changing because i’m animating the scale in a regular way. So I just need to animate each x position in the same way. Let me think…



Okay, with Britzl’s help, I’ve got this far!!

And it’s this simple (once you nest the GOs, with GO16 inside GO15, and GO15 inside GO14, etc):

local function rj(self)
	for k,v in ipairs(self.tableau) do
		sprite.play_flipbook("go"..k, ""..k)
		go.animate("go"..k, "scale.x", go.PLAYBACK_ONCE_PINGPONG, 1.05, go.EASING_LINEAR, 1, k/10)

Now it appears I just need to move the X position of the entire image, in order to keep the whole thing centered as the scales are adjusted. For that, I am going to need one more bit of help.

At the moment, I have this:

function update(self, dt)
	self.offset = go.get("go1", "scale.x") + go.get("go2", "scale.x") + "etc., until" + go.get("go16", "scale.x")

which gives me the (none-linear) overall scale transformation. Once I do some maths to it, I can make it into a table that goes from 0 to 1. Okay, i have done way too much thinking today, I will go to the gym and come back to this.

1 Like