Spawn Multiple sprite sheets

hey guys  today  i am trying to spawn multiple sprite sheets but i seem to get an error “user Value” i never saw this error so i need some help, here my code 

coinsTable = {"bubble"} coins = {} function spawnCoins() ranNum = math.random(#coinsTable) sheet2 = graphics.newImageSheet( coinsTable[ranNum], sheetInfo2:getSheet()) --coins[#coins + 1] = display.newImageRect( coinsTable[ranNum]..".png",128,128 ) coins[#coins].x = display.contentCenterX coins[#coins].y = display.contentCenterY\*3 coins[#coins].id = coinsNum transition.to( coins[#coins], {time = math.random (3000,6000),x = math.random(100,500), y=-570,onComplete = recycle}); screenGroup:insert(coins[#coins]) end totalcoins = 0 timer1= timer.performWithDelay( 8000, spawnCoins, totalcoins ) 

can some one help thanks 

Hi,

Can you post a little bit more code and also the complete error message?

Best regards,

Tomas

I don’t see where you’re creating the display image?  You have a line commented out, but that’s not using your image sheet anyway.

Rob

here more code i made some changes 

local sheetInfo2 = require("bubble")

coinsTable = { "sheets/bubble"} coins = {} function spawnCoins() ranNum = math.random(#coinsTable) coins[#coins + 1] = display.newSprite( sheet2, sequenceData ) coins[#coins].x = display.contentCenterX coins[#coins].y = display.contentCenterY\*3 coins[#coins].id = coinsNum transition.to( coins[#coins], {time = math.random (3000,6000),x = math.random(100,500), y=-570,onComplete = recycle}); 

sheet2 = graphics.newImageSheet( coinsTable[ranNum]..".png", sheetInfo2:getSheet()) screenGroup:insert(coins[#coins]) end totalcoins = 0 timer1= timer.performWithDelay( 8000, spawnCoins, totalcoins )

 sequenceData = { { name="seq1", sheet=sheet1, start=1, count=180, time=9000, loopCount=1}, { name="seq2", sheet=sheet2, start=1, count=79, time=1000, loopCount=0 } }

“the error message states  bad argument #1 to newSprite sheet (ImageSheet expect , got nil )”

 i am not sure why this is not working but thanks for your help :slight_smile:

Hi @seanDp32,

This appears to be a scoping issue: you are trying to create sprites (coins) from the image sheet before you actually create the image sheet. Also, you should not be creating the image sheet inside this function (creating it each time you call the function). The image sheet should be declared above and outside of this function, and then you can create X number of new sprites using that image sheet.

Take care,

Brent

Thanks Brent I am going to try that good solution man

 Hi Brent i follow what you said and it works  thanks man 

Sean 

Hi,

Can you post a little bit more code and also the complete error message?

Best regards,

Tomas

I don’t see where you’re creating the display image?  You have a line commented out, but that’s not using your image sheet anyway.

Rob

here more code i made some changes 

local sheetInfo2 = require("bubble")

coinsTable = { "sheets/bubble"} coins = {} function spawnCoins() ranNum = math.random(#coinsTable) coins[#coins + 1] = display.newSprite( sheet2, sequenceData ) coins[#coins].x = display.contentCenterX coins[#coins].y = display.contentCenterY\*3 coins[#coins].id = coinsNum transition.to( coins[#coins], {time = math.random (3000,6000),x = math.random(100,500), y=-570,onComplete = recycle}); 

sheet2 = graphics.newImageSheet( coinsTable[ranNum]..".png", sheetInfo2:getSheet()) screenGroup:insert(coins[#coins]) end totalcoins = 0 timer1= timer.performWithDelay( 8000, spawnCoins, totalcoins )

 sequenceData = { { name="seq1", sheet=sheet1, start=1, count=180, time=9000, loopCount=1}, { name="seq2", sheet=sheet2, start=1, count=79, time=1000, loopCount=0 } }

“the error message states  bad argument #1 to newSprite sheet (ImageSheet expect , got nil )”

 i am not sure why this is not working but thanks for your help :slight_smile:

Hi @seanDp32,

This appears to be a scoping issue: you are trying to create sprites (coins) from the image sheet before you actually create the image sheet. Also, you should not be creating the image sheet inside this function (creating it each time you call the function). The image sheet should be declared above and outside of this function, and then you can create X number of new sprites using that image sheet.

Take care,

Brent

Thanks Brent I am going to try that good solution man

 Hi Brent i follow what you said and it works  thanks man 

Sean