why do we have to specify name when preparing the sprite prepare("name")?

example:

local sheet2 = sprite.newSpriteSheet( "greenman.png", 128, 128 )  
  
local spriteSet2 = sprite.newSpriteSet(sheet2, 1, 15)  
sprite.add( spriteSet2, "man", 1, 15, 200, 0 ) -- play 15 frames every 200 ms  
  
local instance2 = sprite.newSprite( spriteSet2 )  
instance2.x = 3 \* display.contentWidth / 4 + 30  
instance2.y = baseline - 55  
  
instance2:prepare("man")  
instance2:play()  

why do we have to write instance2.prepare(“man”)

is it possible to have more then one spriteset in same instance?

so I we need to specify

instance2:prepare(“man”)
code …

instance2:prepare(“man-run”)
code…

instance2:prepare(“man-stop”)
code…

If I missunderstood this then why have to specify name. If only one spriteset can be stored in single sprite instance, then I’d like to call my sprite instance

local man = sprite.newSprite( spriteSet2 )

man.prepare(“man”)
man.prepare()

Documentation on this is not perfect, so can someone who understands this better explain why when we run prepare name has to be specified…
[import]uid: 13099 topic_id: 7521 reply_id: 307521[/import]

COUDL NOT EDIT SO I POST THE EDITED HERE:
example:

local sheet2 = sprite.newSpriteSheet( "greenman.png", 128, 128 )  
  
local spriteSet2 = sprite.newSpriteSet(sheet2, 1, 15)  
sprite.add( spriteSet2, "man", 1, 15, 200, 0 ) -- play 15 frames every 200 ms  
  
local instance2 = sprite.newSprite( spriteSet2 )  
instance2.x = 3 \* display.contentWidth / 4 + 30  
instance2.y = baseline - 55  
  
instance2:prepare("man")  
instance2:play()  

why do we have to write instance2.prepare(“man”)

is it possible to have more then one spriteset in same instance?

it would then make reason to need to specify name in prepare, otherwise it’s just confusing and unnecessary…

local sheet2 = sprite.newSpriteSheet( "greenman.png", 128, 128 )  
  
local spriteSet2 = sprite.newSpriteSet(sheet2, 1, 15)  
sprite.add( spriteSet2, "man", 1, 15, 200, 0 ) -- play 15 frames every 200 ms  
local sheet3 = sprite.newSpriteSheet( "greenman-jumping.png", 128, 128 )  
sprite.add( spriteSet3, "man-jump", 1, 15, 200, 0 ) -- play 15 frames every 200 ms  
  
local instance2 = sprite.newSprite( spriteSet2 )  
instance2 = sprite.newSprite( spriteSet3 )  
instance2.x = 3 \* display.contentWidth / 4 + 30  
instance2:prepare("man")  
instance2:prepare("man-jump")  

If I missunderstood this then why have to specify name. If only one spriteset can be stored in single sprite instance, then I’d like to call my sprite instance

local man = sprite.newSprite( spriteSet2 )

man.prepare(“man”)
man.prepare()

Documentation on this is not perfect, so can someone who understands this better explain why when we run prepare name has to be specified…

[import]uid: 13099 topic_id: 7521 reply_id: 26662[/import]

is it possible to have more then one spriteset in same instance?

yep, you are understanding it correctly, although you are getting the terminology a little mixed up. It’s only one spriteset, but a spriteset can include multiple named sequences of frames. [import]uid: 12108 topic_id: 7521 reply_id: 26669[/import]

It seems unnecessary to you because you’re splitting up two animations into two separate sheets, which kind of defeats the purpose of sprite sheets. You could (should) load “greenman” and “greenman jumping” as a single spritesheet instead of loading two separate pngs. Then you create two sequences: “man”, which shows frames 1-15 and “man-jump” which shows frames 16-30, or however your sprite lua file orders them. [import]uid: 41305 topic_id: 7521 reply_id: 26673[/import]

Hi thanks for the answer, could you please give me an example of that, I dont see any good examples in documentation for that.

Would this spriteset have to get these multiple sequence from the same spritesheet or would it be possible to use multiple spritesheet containing different animations and put them into ona and the same spriteset giving them different names?

Please show me simple working example, I need to understand this or my code will be mess :slight_smile: [import]uid: 13099 topic_id: 7521 reply_id: 26672[/import]

if my spritesheet for just one simple animation takes 1024x1024 then I have a problem, because I have one big character on the screen with dimension of 213x320 for just single frame, I fill up that 1024x1024 in no time.

So having all possible sequences and animation for one character in one spritesheet will not be possible, I have to split everything into different spritesheets.

So is it possible to use different spritesheets and put them into one spriteset? And could I see some example of this. [import]uid: 13099 topic_id: 7521 reply_id: 26674[/import]

for example this does not work for me, what am I doing wrong here:

local blink = sprite.newSpriteSheetFromData( "blink\_01.png", require("blink\_01").getSpriteSheetData() )  
local spriteSet = sprite.newSpriteSet(blink, 1, 13)  
sprite.add(spriteSet, "blink",1,13,100,1)  
  
local spriteInstance = sprite.newSprite(spriteSet)  
  
local anim\_turn\_left = sprite.newSpriteSheetFromData( "anim\_turn\_left.png", require("anim\_turn\_left").getSpriteSheetData() )  
spriteSet = sprite.newSpriteSet(anim\_turn\_left, 1, 16)  
sprite.add(spriteSet, "anim\_turn\_left", 1, 16, 700, 1)  
  
spriteInstance = sprite.newSprite(spriteSet)  

C:\Users***\workspace\Corona\Muppet\main.lua:35: bad argument #-2 to ‘prepare’ (sprite.SpriteSequence expected, got nil)
stack traceback:
[C]: ?
[C]: in function ‘prepare’
C:\Users***\workspace\Corona\Muppet\main.lua:35: in function 'b
prepare functions:

[code]
local function blinkPlay( event )
print (“blink”)

–spriteInstance.isVisible = true
–spriteInstance2.isVisible = false

spriteInstance:prepare(“blink”)
spriteInstance:play()

–timer.cancel(blinkTimer)
end

local function turnLeftPlay( event )
print (“turn left”)

–spriteInstance.isVisible = false
–spriteInstance2.isVisible = true

spriteInstance:prepare(“anim_turn_left”)
spriteInstance:play()

–timer.cancel(blinkTimer)
end
[/code] [import]uid: 13099 topic_id: 7521 reply_id: 26677[/import]

Look into a sprite sheet creator like TexturePacker or Zwoptex (both have free trials IIRC). They’ll take individual pngs and merge them into one sheet. If your animation sizes require that you need more than one sheet, then there’s really nothing to do about that. But your original question was why you have to “prepare” sprites, and the answer is because normally there are many animation sequences on a single sheet. You’re not doing that, so “prepare” is just an extra step for you, but it’s something that’s needed for spritesheets used the usual way. [import]uid: 41305 topic_id: 7521 reply_id: 26681[/import]

@Nermion

You may also find SpriteGrabber of some help to you. [import]uid: 7356 topic_id: 7521 reply_id: 26884[/import]