Multi Sprite Solution with new display.newsprite()

Hi Everyone,
I’ve been trying to get on top of using the new Sprite API and I’m coming across one stumbling block. I know a lot of people were interested in having sprite sequences spread across multiple sprite sheets and I was wondering if anyone has managed this with the new API?

Here’s an example of code to explain what I’m trying to do:

[code]
local options =
{
width = 250,
height = 250,
numFrames = 45
}

local imageSheet1 = graphics.newImageSheet( “walking_running.png”, options )
local imageSheet2 = graphics.newImageSheet( “talking_jumping.png”, options )

local sequenceData = {
{ name=“walking”, start=1, count=45, loopCount=1, imageSheet=imageSheet1, time=2000 },
{ name=“running”, start=1, count=45, loopCount=1, imageSheet=imageSheet1, time=2000 },
{ name=“talking”, start=1, count=45, loopCount=1, imageSheet=imageSheet2, time=2000 },
{ name=“jumping”, start=1, count=45, loopCount=1, imageSheet=imageSheet2, time=2000 }
}

–After Character object (below) finishes an animation, play Talking sequence automatically
local function nextAnimation(event)
if event.phase == ‘ended’ then
– ** Change to another animation sequence here
event.target:setSequence(“talking”) – But this set of frames is on ImageSheet2
event.target:play()
end
end
local character = display.newSprite( imageSheet, sequenceData ) – ** What if I want to access frames on ImageSheet2?
character.x, character.y = 500, 500
character:addEventListener(“sprite”, nextAnimation)
character:setSequence(“walking”)
character:play()
[/code] [import]uid: 156990 topic_id: 32739 reply_id: 332739[/import]

Hi Michael,
I don’t think this has been implemented yet. I know that it has received some degree of requests, but in comparison to other Corona feature requests, even some others pertaining to sprites, this one seems to have fallen fairly low. I know that’s not a great answer, but you can continue to use the old sprite library, or combine you image sheets, if possible.

Brent [import]uid: 9747 topic_id: 32739 reply_id: 130263[/import]

Hi Michael,
I don’t think this has been implemented yet. I know that it has received some degree of requests, but in comparison to other Corona feature requests, even some others pertaining to sprites, this one seems to have fallen fairly low. I know that’s not a great answer, but you can continue to use the old sprite library, or combine you image sheets, if possible.

Brent [import]uid: 9747 topic_id: 32739 reply_id: 130263[/import]

Walter posted a message recently in the original thread regarding this feature:

http://developer.coronalabs.com/forum/2012/06/21/displaynewmultisprite-needed#comment-129922

But I don’t think it clarifies anything. [import]uid: 33275 topic_id: 32739 reply_id: 130279[/import]

Walter posted a message recently in the original thread regarding this feature:

http://developer.coronalabs.com/forum/2012/06/21/displaynewmultisprite-needed#comment-129922

But I don’t think it clarifies anything. [import]uid: 33275 topic_id: 32739 reply_id: 130279[/import]

Hi Brent / SegaBoy,

Yeah I saw that. Fair play to him for posting it up but as you said it doesn’t relate to the multi sheet issue, only references the multi-sequence functionality.

I really can’t understand the advantage of being able to apply individual imagesheets to sequences in a sequenceData table if at the end of the day you need to specify a specific imagesheet when drawing the display object.

If the imageSheet parameter was optional in the display.newSprite() function and required in the sequenceData, I think it would make more sense. We could create something as per the example Walter gave in the thread:

local sequenceData = {  
 { name="walking", imageSheet=sheet1, start=1, count=3 },  
 { name="running", imageSheet=sheet1, frames={ 3, 4, 5, 6, 7, 8 }, time=50, loopCount=4 },  
 { name="jumping", imageSheet=sheet2, start=9, count=13, time=300 },  
}  
   
display.newSprite( sequenceData )  

I’m not sure what the consequences would be of swapping the optional parameters in regards to other APIs pointing to these functions, but it makes perfect sense to me if we could get the features working this way.

What do you guys think?

Michael [import]uid: 156990 topic_id: 32739 reply_id: 130286[/import]

I’m in agreement - it needs to have the same functionality as the older sprite method - unless I’m really missing out on something. [import]uid: 33275 topic_id: 32739 reply_id: 130288[/import]

Hi Brent / SegaBoy,

Yeah I saw that. Fair play to him for posting it up but as you said it doesn’t relate to the multi sheet issue, only references the multi-sequence functionality.

I really can’t understand the advantage of being able to apply individual imagesheets to sequences in a sequenceData table if at the end of the day you need to specify a specific imagesheet when drawing the display object.

If the imageSheet parameter was optional in the display.newSprite() function and required in the sequenceData, I think it would make more sense. We could create something as per the example Walter gave in the thread:

local sequenceData = {  
 { name="walking", imageSheet=sheet1, start=1, count=3 },  
 { name="running", imageSheet=sheet1, frames={ 3, 4, 5, 6, 7, 8 }, time=50, loopCount=4 },  
 { name="jumping", imageSheet=sheet2, start=9, count=13, time=300 },  
}  
   
display.newSprite( sequenceData )  

I’m not sure what the consequences would be of swapping the optional parameters in regards to other APIs pointing to these functions, but it makes perfect sense to me if we could get the features working this way.

What do you guys think?

Michael [import]uid: 156990 topic_id: 32739 reply_id: 130286[/import]

I’m in agreement - it needs to have the same functionality as the older sprite method - unless I’m really missing out on something. [import]uid: 33275 topic_id: 32739 reply_id: 130288[/import]

Any update from Corona Staff on the likelihood of this being implemented in a future build?

Michael [import]uid: 156990 topic_id: 32739 reply_id: 131590[/import]

Any update from Corona Staff on the likelihood of this being implemented in a future build?

Michael [import]uid: 156990 topic_id: 32739 reply_id: 131590[/import]

Hello Michael, @SegaBoy, etc.
I figured it out! You can, in fact, do multi-sprites using the new API. It requires adding a “sheet” parameter to each sequence, specifying which image sheet that sequence should pull its frames from.

Like this…

-- 1st image sheet  
local sheetData1 = { width=64, height=64, numFrames=6, sheetContentWidth=384, sheetContentHeight=64 }  
local sheet1 = graphics.newImageSheet( "mySheet1.png", sheetData1 )  
  
-- 2nd image sheet  
local sheetData2 = { width=64, height=64, numFrames=6, sheetContentWidth=384, sheetContentHeight=64 }  
local sheet2 = graphics.newImageSheet( "mySheet2.png", sheetData2 )  
  
-- In your sequences, add the parameter 'sheet=' referencing which image sheet the sequence should use  
local sequenceData = {  
 { name="seq1", sheet=sheet1, start=1, count=6, time=220, loopCount=0 },  
 { name="seq2", sheet=sheet2, start=1, count=6, time=220, loopCount=0 }  
}  
  
local myAnimation = display.newSprite( sheet1, sequenceData )  
myAnimation.x = display.contentWidth/2 ; myAnimation.y = display.contentHeight/2  
myAnimation:play()  
  
-- After a short time, swap the sequence to 'seq2' which uses the second image sheet  
local function swapSheet()  
 myAnimation:setSequence( "seq2" )  
 myAnimation:play()  
end  
timer.performWithDelay( 2000, swapSheet )  

I’m going to update the actual Corona documentation on this soon. Until then, go ahead and experiment with it. I tested it in an actual project on my side and it works fine.

Thanks for being patient on this; I kicked the can down road for too long but didn’t forget about it. :slight_smile:

Brent Sorrentino [import]uid: 200026 topic_id: 32739 reply_id: 132995[/import]

Hello Michael, @SegaBoy, etc.
I figured it out! You can, in fact, do multi-sprites using the new API. It requires adding a “sheet” parameter to each sequence, specifying which image sheet that sequence should pull its frames from.

Like this…

-- 1st image sheet  
local sheetData1 = { width=64, height=64, numFrames=6, sheetContentWidth=384, sheetContentHeight=64 }  
local sheet1 = graphics.newImageSheet( "mySheet1.png", sheetData1 )  
  
-- 2nd image sheet  
local sheetData2 = { width=64, height=64, numFrames=6, sheetContentWidth=384, sheetContentHeight=64 }  
local sheet2 = graphics.newImageSheet( "mySheet2.png", sheetData2 )  
  
-- In your sequences, add the parameter 'sheet=' referencing which image sheet the sequence should use  
local sequenceData = {  
 { name="seq1", sheet=sheet1, start=1, count=6, time=220, loopCount=0 },  
 { name="seq2", sheet=sheet2, start=1, count=6, time=220, loopCount=0 }  
}  
  
local myAnimation = display.newSprite( sheet1, sequenceData )  
myAnimation.x = display.contentWidth/2 ; myAnimation.y = display.contentHeight/2  
myAnimation:play()  
  
-- After a short time, swap the sequence to 'seq2' which uses the second image sheet  
local function swapSheet()  
 myAnimation:setSequence( "seq2" )  
 myAnimation:play()  
end  
timer.performWithDelay( 2000, swapSheet )  

I’m going to update the actual Corona documentation on this soon. Until then, go ahead and experiment with it. I tested it in an actual project on my side and it works fine.

Thanks for being patient on this; I kicked the can down road for too long but didn’t forget about it. :slight_smile:

Brent Sorrentino [import]uid: 200026 topic_id: 32739 reply_id: 132995[/import]