Spawn Animated Sprite

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 

Hi @sobh,

Sprites do not automatically begin playing (animating) when you create them. You should use the “:play()” method to start them:

https://docs.coronalabs.com/api/type/SpriteObject/play.html

And here’s a reference to all of the sprite methods/properties for your convenience:

https://docs.coronalabs.com/api/type/SpriteObject/index.html

Best regards,

Brent

Hi @ Brent

Thanks for the info . but i already played the sprit ( the frames ) using

animatedBat:play() – start playing the sprite Frames

i just not able to spawn more than one actor ( sprite ) on the screen using the above code . but i can spawn if i only use normal images

Hi @sobh,

What is “animatedBat”? In your code above, you create the bats like this:

[lua]

Bats[i] = display.newSprite( sheet_animatedBat, sequences_animatedBat );

[/lua]

So, just use the :play() API on that same object:

[lua]

Bats[i]:play()

[/lua]

Brent

Hi @ Brent

yea my mistake )) i just didn’t start playing ( animated ) the second spawn bats …

Thanks again to hint to it

Hi @sobh,

Sprites do not automatically begin playing (animating) when you create them. You should use the “:play()” method to start them:

https://docs.coronalabs.com/api/type/SpriteObject/play.html

And here’s a reference to all of the sprite methods/properties for your convenience:

https://docs.coronalabs.com/api/type/SpriteObject/index.html

Best regards,

Brent

Hi @ Brent

Thanks for the info . but i already played the sprit ( the frames ) using

animatedBat:play() – start playing the sprite Frames

i just not able to spawn more than one actor ( sprite ) on the screen using the above code . but i can spawn if i only use normal images

Hi @sobh,

What is “animatedBat”? In your code above, you create the bats like this:

[lua]

Bats[i] = display.newSprite( sheet_animatedBat, sequences_animatedBat );

[/lua]

So, just use the :play() API on that same object:

[lua]

Bats[i]:play()

[/lua]

Brent

Hi @ Brent

yea my mistake )) i just didn’t start playing ( animated ) the second spawn bats …

Thanks again to hint to it