newSpriteMultiSet bug?

Hi, I am a really new and this is maybe not a bug, and if so be kind to me:)

I am having some spritesheets but I cant manage to get them to play without jitter. I have been struggling with this for more then a week now, and I am about to give up this…Even if i specify what frames to play, Corona picks some other…and the animation is jittering and looks bad…
I do have 2 spritesheets with 60 different sprites. Each spritesheet contains 2 different sequences. Total is 120 frames.

Fly right: frames 1 -> 40 : total 40
Turn left: frames 41 ->60 : total 20

Fly left: frames 61 -> 100 : total 40
Turn right: frames 101 - 120: total 20

I dont know how much code you want to see but I assume that this is the key…

flyRightSheet = sprite.newSpriteSheetFromData( "right.png", require("right").getSpriteSheetData() )  
flyLeftSheet = sprite.newSpriteSheetFromData( "left.png", require("left").getSpriteSheetData() )  
  
   
  
spriteSet1 = sprite.newSpriteMultiSet(   
{  
 { sheet = flyRightSheet, frames = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60 }},  
 { sheet = flyLeftSheet, frames = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60}},  
  
}  
)  
  
sprite.add(spriteSet1,"fly\_right",1,40,1000,0)  
sprite.add(spriteSet1,"turn\_left",41,20,1000,1)  
  
sprite.add(spriteSet1,"fly\_left",61,40,1000,0)  
sprite.add(spriteSet1,"turn\_right",101,20,1000,1)  
  

Is there something wrong with the code? I can send you the project files if someone request this.

Joakim
[import]uid: 81188 topic_id: 15320 reply_id: 315320[/import]

Hey there,

Can you please tell me what size your sprite sheets are? Are they larger than 1024x1024?

Peach [import]uid: 52491 topic_id: 15320 reply_id: 56648[/import]

Hi Peach and thanks for your reply!

The spriteseheets have the size of 1024 x 1024. There is some problems with the frames handling, since that fact that it plays frames that belongs to another sequence. Could I email you the source or do you have any other ideas?

Joakim [import]uid: 81188 topic_id: 15320 reply_id: 56665[/import]

Ok, I have done some more investigation and this is what I have came up with:

If I play each sequence just by itself in a loop - it is correct.

As soon as I run all my code that controls the player and changes the sequences it mixes frames from both spritesheets. If I am changing from right to left it picks frame 14 from the other sheet, and frame 1 when i run vice versa.

So I guess that my logic is bad…

\_W = display.contentWidth  
\_H = display.contentHeight  
  
system.setIdleTimer( false )  
  
local txt = display.newText("DEBUG: ", 200, 10, native.systemFontBold, 14)   
SPRITE\_STATE = ""  
GUI\_STATE = ""  
  
display.setStatusBar( display.HiddenStatusBar )  
  
local physics = require("physics")  
system.activate( "multitouch" )  
  
physics.start()  
physics.setGravity(0, 0)   
physics.setScale(40)  
  
require "sprite"  
  
flyRightSheet = sprite.newSpriteSheetFromData( "right.png", require("right").getSpriteSheetData() )  
flyLeftSheet = sprite.newSpriteSheetFromData( "left.png", require("left").getSpriteSheetData() )  
  
   
  
spriteSet1 = sprite.newSpriteMultiSet(   
{  
 { sheet = flyRightSheet, frames = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60 }},  
 { sheet = flyLeftSheet, frames = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60}},  
  
}  
)  
  
sprite.add(spriteSet1,"fly\_right",1,40,1000,0)  
sprite.add(spriteSet1,"turn\_left",41,20,1000,0)  
  
sprite.add(spriteSet1,"fly\_left",61,40,1000,0)  
sprite.add(spriteSet1,"turn\_right",101,20,1000,0)  
  
local function getSpriteSeq(event)  
  
 SPRITE\_STATE = event.sprite.sequence  
 txt.text = event.sprite.sequence  
  
end  
  
local function spriteListener( event )  
  
if(event.sprite.currentFrame==40) then  
 if(GUI\_STATE=="TL") then  
  
 player:prepare("turn\_left")  
 player:play()   
 GUI\_STATE =""  
  
 end  
end  
  
if(SPRITE\_STATE=="turn\_left" and event.sprite.currentFrame==20) then  
 player:prepare("fly\_left")  
 player:play()   
end  
  
if(event.sprite.currentFrame==40) then  
 if(GUI\_STATE=="TR") then  
  
 player:prepare("turn\_right")  
 player:play()   
 GUI\_STATE =""  
  
 end  
end  
  
if(SPRITE\_STATE=="turn\_right" and event.sprite.currentFrame==20) then  
 player:prepare("fly\_right")  
 player:play()   
end  
  
  
 txt.text = SPRITE\_STATE .. " - " .. event.sprite.currentFrame  
  
  
end  
  
 player = sprite.newSprite( spriteSet1 )  
 player.xScale = 1.0  
 player.yScale = 1.0  
 player.x = 200  
 player.y = 180  
 player.objectType = "player"  
 player:addEventListener("sprite", getSpriteSeq)  
 player:addEventListener( "sprite", spriteListener )  
 physics.addBody(player,{friction=.9, bounce = .1})  
 player:prepare("fly\_right")  
 player:play()   
local function fly( event )  
  
 if not (player==nil) then  
 --\>player:applyLinearImpulse(0, -.2, player.x, player.y)  
 end  
  
end  
  
local function moveforward( event)  
  
 --\> Lagra startpunkterna när man brjar dra  
 if(event.phase=="began") then  
 x0 = event.x  
  
 end  
 --\> Check direction of swipe  
 if(event.phase=="moved") then  
  
 if(player==nil) then  
  
 else   
  
 if(x0 \< event.x) then  
  
 --\> FLYGFRAMÅT  
 --\>player:applyLinearImpulse(.02, 0, player.x, player.y)   
 if(SPRITE\_STATE=="fly\_left") then  
 display.getCurrentStage():setFocus(nil)  
 --\>player:scale(1, 1)  
 GUI\_STATE = "TR"  
 --\>player:prepare("turn\_right")  
 --\>player:play()   
 end  
 else  
 --\> FLYGBAKÅT  
 --\>player:applyLinearImpulse(-.02, 0, player.x, player.y)  
 if(SPRITE\_STATE=="fly\_right") then  
 display.getCurrentStage():setFocus(nil)  
 --\>player:scale(-1, 1)  
 GUI\_STATE = "TL"   
 --\>player:prepare("turn\_left")  
 --\>player:play()   
 end  
 end  
  
 end  
  
 end  
 display.getCurrentStage():setFocus( nil )  
   
end  
  
local function onCollision ( event )  
  
 local type1 = event.object1.objectType  
 local type2 = event.object2.objectType  
  
end  
  
function reStart()  
 createPlayer()  
 Runtime:addEventListener ( "collision", onCollision )  
end  
  
local function onPostCollision( event )  
 txt.text = event  
end   
Runtime:addEventListener("tap", fly)  
Runtime:addEventListener("touch", moveforward)  
  

I really hope someone can look at this and try to figure out why I am having thsi problems with the frames.

Best regards, Joakim

[import]uid: 81188 topic_id: 15320 reply_id: 56940[/import]

The problem occurs first when I try to play the third sequence, but the second is fine?

It is in this codeblock:

  
if(SPRITE\_STATE=="turn\_left" and event.sprite.currentFrame==20) then  
 player:prepare("fly\_left")  
 player:play()   
end  
  

It starts to show frame 14 from the seq “fly_right” and then plays the “fly_left” sequence as it should???

Please, any advises!

Joakim [import]uid: 81188 topic_id: 15320 reply_id: 56952[/import]

If I put a delay of a couple of ms within the codeblock above then it works…is this a bug or a code error?

Joakim - talking to my self… [import]uid: 81188 topic_id: 15320 reply_id: 56953[/import]

Hey again Joakim,

Sorry - sometimes it takes a little to get back to a thread. (Time differences, etc.)

I’m glad you have found a solution with a delay; there are a few occasions where you need to use one to give everything enough time to “catch up”.

I will pass this on however to have someone who is pro with sprites take a look and see if there’s anything we can do about it :wink:

Peach :slight_smile: [import]uid: 52491 topic_id: 15320 reply_id: 57083[/import]

No problems, but if i add a delay - the animation looks bad. I would be more then happy if there is a way to solve this in a better way. For me it looks like a bug?

Joakim [import]uid: 81188 topic_id: 15320 reply_id: 57095[/import]

Ok, so this is what i camed up with.

First of all, should it be possible to have more then one sheet attached to a sprite?

If so, then this is a bug. If I am using only one sheet, it works perfect. As soon as I add more then one sheet it bug out.

Joakim [import]uid: 81188 topic_id: 15320 reply_id: 57133[/import]

Are you able to submit a sub with some code to replicate the problem? That would help in seeing what’s up. http://developer.anscamobile.com/forms/support

For the delay, how many ms is it set too currently? [import]uid: 52491 topic_id: 15320 reply_id: 57232[/import]

I will file that later and provide a sample of code.

I tried 60 ms but it worked best with 100ms.

Joakim [import]uid: 81188 topic_id: 15320 reply_id: 57272[/import]