I want to make a simple animation using a number of images. For example: 001.png to 100.png
There are two ways to make this animation:
1. I need to create a class to display the image 001 to 100 as an animation. I suspect that I need to using the loop function. But I do not know how many CPU resources should eat this way.
2. To convert images from 001 to 100 in GIF format. But that's not possible, right now, because Codea does not support to import GIF images.
If the idea with GIF cannot be applied now. Please give me a class to animate the images from 001 to 100. Have a nice day!
if picno<10 then
sprite("Dropbox:00"..picno)
elseif picno<100 then
sprite("Dropbox:0"..picno)
else
sprite("Dropbox:"..picno)
End
if picno==100 then
picno =0
else
picno = picno + 1
end
Not actual code, just an idea from scratch out of my head… Supports up to 999 pngs… Hope it helps, the CPU is ok with it, but I don’t know about the ram and 100 pngs…
Inviso, Your code is very easy to use / understand.
Connorbot999, Your code looks pretty good and even more.
But I do not understand this part: function setup() smooth() iparameter("frameDelay", 1, 25, 10) animation = Animation({("Small World:Heart"),("Small World:Heart Gold"),},10) end
I want to automatically put my spritepack which containing 100 images, not every image, separately. animation = Animation({("Small World:001"),("Small World:002"),},10)
-- Use this function to perform your initial setup
function setup()
sprites = {}
for i=0,5 do
sprites[i+1] = "Dropbox:mysprite_"..i
end
time = 0
sprNr = 1
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(40, 40, 50)
time = time + DeltaTime
-- draw ten sprites per second
if time >= 0.1 then
name = sprites[sprNr%4+1]
time = 0
sprNr = sprNr + 1
end
spriteMode(CENTER)
sprite(name, WIDTH/2, HEIGHT/2)
end
As an alternative, if you have all the images in a single sprite sheet. In this example the sprite sheet would contain rows of 5, 32 by 32 sprites and 12 rows in total. The fourth row from the bottom would be displayed (yanim=3, starting from 0)
function setup()
m = mesh()
m.texture = "Dropbox:spritesheet" --sprite sheet
recti = m:addRect(WIDTH/2,HEIGHT/2,32,32)
parameter("animspeed", 1, 10, 6) --user defined animation speed
xanim=0
yanim=3 --row of sprites to display starting from the bottom
animdelay=0
numacross=5 --number of columns of sprites
numdown=12 --number of rows of sprites
end
function draw()
background(40, 40, 50)
noSmooth()
m:setRectTex(recti,xanim*(1/numacross), yanim*(1/numdown),(1/numacross),(1/numdown))
if animdelay>animspeed then
xanim = xanim + 1
animdelay=0
end
if xanim>numacross-1 then
xanim=0
end
animdelay = animdelay + 1
m:draw()
end