Sprite Disapperaing using Sprite Sheet Set

4 replies [Last post]
Daniel W.'s picture
Daniel W.
User offline. Last seen 3 days 7 hours ago. Offline
Joined: 13 Jan 2011

Hello Corona Community!

I have a problem using the newSpriteSet. I combined a 22 sprites: 1-14 of jumping and 15-22 of running. The problem with this is when I use the "run" sprite set, the sprite disappears and then restarts. I've attached a link to a YouTube video showing what's happening. Is there a work-around or is there something wrong with my code?

http://youtu.be/29861VEVnPo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
local sheetData = require ('santa')
    local data = sheetData.getSpriteSheetData()
    local spriteSheet = sprite.newSpriteSheetFromData( "images/santa.png", data )
    
    local santaRunSet = sprite.newSpriteSet(spriteSheet, 1, 22)
    sprite.add( santaRunSet, "jump", 1, 14, 500, -2)
    sprite.add( santaRunSet, "run", 15, 22, 400, -2)
    
    local santa = sprite.newSprite( santaRunSet )
    santa.x = 280
    santa.y = 100
     
    physics.addBody( santa, "dynamic", { friction=0.5, bounce=0.3 } ) 
     
    santa:prepare("run")
    santa:play()

Replies

@RSCdev's picture
@RSCdev
User offline. Last seen 2 hours 38 min ago. Offline
Joined: 6 Sep 2011

-

peach pellen's picture
peach pellen
User offline. Last seen 1 day 12 hours ago. Offline
Staff
Joined: 12 Apr 2011

Change line 7 to this;
sprite.add( santaRunSet, "run", 15, 8, 400, -2)

You had 15, 22 - which says you want to start that sequence at frame 15 and go for 22 frames. You in fact want to start at frame 15 and play 8 frames. (15 to 22 = 8 frames, including frame 15.)

TLDR; The second number is how many frames in the sequence, NOT the number of the final frame in the sequence.

Try that - should fix it up.

Peach :)

Daniel W.'s picture
Daniel W.
User offline. Last seen 3 days 7 hours ago. Offline
Joined: 13 Jan 2011

Oooohhhhh! Thank you Peach! Ansca is lucky to have you helping people on the Corona SDK forums!

peach pellen's picture
peach pellen
User offline. Last seen 1 day 12 hours ago. Offline
Staff
Joined: 12 Apr 2011

Not a problem at all - thanks for the very kind words, I really appreciate that.

Peach :)

Viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.