Sprite sheet static image

hello :slight_smile:

i need to change a image with a sprite sheet, i never used sprite sheets and need some help, i saw this code:

local tileSheet = sprite.newSpriteSheet("tiles.png", 64, 64)  
local tileSet = sprite.newSpriteSet(tileSheet, 1, 10)  
local tile = sprite.newSprite(tileSet)  
tile.currentFrame = 5  

i need something like a:

if #myvariable == 1 then   
-- need to show and image with number one, that is on the sprite sheet  
elseif #myvariable ==2 then  
-- need to show and image with number one, that is on the sprite sheet  
..  
..  
..  

i need to learn how i can change the image on a sprite sheet and the signification of this part:
local tileSet = sprite.newSpriteSet(tileSheet, 1, 10), the number 1 and 10

Thanks again corona community [import]uid: 26056 topic_id: 15830 reply_id: 315830[/import]

local spriteSheet = sprite.newSpriteSheet( “sprite.png”, 100, 100 )
–> means, each frame in sprite.png is 100x100 pixels size

local spriteSet = sprite.newSpriteSet (spriteSheet, 1, 4)
–> you are creating a sprite-set - that has ‘4’ frames - starting from frame ‘1’ - from the ‘spriteSheet’

sprite.add (spriteSet, “play-frame-1-2-3”, 1, 3, 1000, 1)
–> you are creating a sequence of frames to play
–> Here: you want to play ‘3’ frames - starting from frame ‘1’ , i.e. frame 1,2,3 - in 1000milli-seconds.
–> last parameter is how many time you want to play the same sequence. Here, ‘1’ means it will play once.

local spriteInstance = sprite.newSprite( spriteSet )
spriteInstance:prepare (“play-frame-1-2-3”)
spriteInstance:play()
–> now you will actually playing ‘frame 1 2 3’

Hope it helps.

  • Chinta
    [import]uid: 63121 topic_id: 15830 reply_id: 58504[/import]

try using SpriteGrabber it makes working with spritesheets abit easier
http://developer.anscamobile.com/code/spritegrabber-spritesheets-two-lines [import]uid: 7911 topic_id: 15830 reply_id: 58530[/import]

Thanks people, it help me:) [import]uid: 26056 topic_id: 15830 reply_id: 58730[/import]

I didn’t know about SpriteGrabber before. Otherwise I would have used it in my game.
I have implemented all of my sprites in crude raw way… :slight_smile:
Thanks for sharing it Jstrahan !
[import]uid: 63121 topic_id: 15830 reply_id: 58994[/import]

welcome [import]uid: 7911 topic_id: 15830 reply_id: 58997[/import]