Skip to content

Commit a60ecb8

Browse files
committed
Add new example to stack all sprites in one
1 parent 93362b3 commit a60ecb8

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Stack All Sprites in One.lua

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
-- This example shows how to create a new sprite stacking all the
2+
-- other sprites each in one layer.
3+
4+
if #app.sprites < 1 then
5+
return app.alert "You should have at least one sprite opened"
6+
end
7+
8+
local bounds = Rectangle()
9+
for i,sprite in ipairs(app.sprites) do
10+
bounds = bounds:union(sprite.bounds)
11+
end
12+
13+
local function getTitle(filename)
14+
return filename:match("^.+/(.+)$")
15+
end
16+
17+
local newSprite = Sprite(bounds.width, bounds.height)
18+
local firstLayer = newSprite.layers[1]
19+
newSprite:deleteCel(newSprite.cels[1])
20+
for i,sprite in ipairs(app.sprites) do
21+
if sprite ~= newSprite then
22+
while #newSprite.frames < #sprite.frames do
23+
newSprite:newEmptyFrame()
24+
end
25+
local newLayer = newSprite:newLayer()
26+
newLayer.name = getTitle(sprite.filename)
27+
for j,frame in ipairs(sprite.frames) do
28+
local cel = newSprite:newCel(newLayer, frame)
29+
cel.image:drawSprite(sprite, frame)
30+
end
31+
end
32+
end
33+
newSprite:deleteLayer(firstLayer)
34+
app.activeFrame = 1

0 commit comments

Comments
 (0)