hi
this is my second day trying to learn more . and today i am trying to spawn an animated Sprite but i am not able to do that .
i can easly spawn images but i cant spawn animated sheets
here is the code that create the sprite sheet with the animated frames
– Animated Bat Pics —
local sheetOptions =
{
width = 80,
height = 70,
numFrames = 5
}
local sheet_animatedBat = graphics.newImageSheet( “BatDownRun.png”, sheetOptions )
local sequences_animatedBat = {
– consecutive frames sequence
{
name = “normalRun”,
frames = {1,2,3},
time = 500,
loopCount = 0,
loopDirection = “forward”
},
{
name = “falldown”,
frames = {4,5},
time = 500,
loopCount = 0,
loopDirection = “forward”
},
}
local animatedBat = display.newSprite( sheet_animatedBat, sequences_animatedBat )
animatedBat:play() – start playing the sprite Frames
animatedBat.name = “TheBat”
now i am trying to spawn that animated sprite using a table and a function
local Bats = {}
local i = 0
local function spawnBats()
for i= 1,10 do
Bats[i] = display.newSprite( sheet_animatedBat, sequences_animatedBat );
Bats[i].y = (math.random(100,200) * i)
Bats[i].x = (math.random(100,200) * i)
–Bats[i].speed = 4
–physics.addBody( Bats[i], “static”, { friction=1.0, density=1.0, bounce=0, radius=30,} )
–Bats[i].enterFrame = moveBats
–Runtime:addEventListener(“enterFrame”, Bats[i])
transition.to ( Bats[i], {time=3000,x=100,y=0} )
end
end
timer.performWithDelay(500, spawnBats, 10)
and it did spawn them but it is not animated