Is it possible to change the sprite sheet of an object, so when a character it running it plays a sprite sheet, but when it jumps it plays a different one? [import]uid: 116264 topic_id: 24353 reply_id: 324353[/import]
Yes it is, this gives an example of using 4 different sequences for walking four different directions - could easily add jumping; http://techority.com/2011/05/01/using-sprites-in-your-corona-iphone-application/
Peach
[import]uid: 52491 topic_id: 24353 reply_id: 98440[/import]
Thanks thats very useful. I’ve managed to make the sprite change, although something odd happens. When it changes, all of the images play really quickly and then the sprite disappears for the remainder of the time, and this just repeats. Any suggestions as to how to fix it? The code I am using is:
local sheet1 = sprite.newSpriteSheet( "man3.png", 120, 140 )
local spriteSet1 = sprite.newSpriteSet(sheet1, 1, 12)
sprite.add( spriteSet1, "running", 1, 6, 300, 0 )
sprite.add( spriteSet1, "crouching", 7,12, 300, 0)
local man = sprite.newSprite( spriteSet1 )
man:prepare("running"); man:play()
local function Crouch (event)
if event.phase == "began" and man.isGrounded == true then
man.rotation = -65
man:prepare("crouching"); man:play()
elseif event.phase == "ended" and man.isGrounded == true then
man:prepare("running"); man:play()
man.rotation = 16
man.y = man.y -10
end
end
crouchbtn:addEventListener("touch", Crouch)
[import]uid: 116264 topic_id: 24353 reply_id: 98533[/import]
Dont forget to pause the previous anim i think. [import]uid: 21331 topic_id: 24353 reply_id: 98535[/import]
I’ve done that and it still isnt working. Any other suggestions? [import]uid: 116264 topic_id: 24353 reply_id: 98540[/import]
I started to notice some issues with the old sprite library, and I am in the process of moving to the new one (imageSheets) to see if they go away. As far as testing this, it will have to wait till i get home. I’ll check on it and see if someone else picks it up, if not I’ll see what i can find. [import]uid: 21331 topic_id: 24353 reply_id: 98547[/import]
I am working on it. One problem I see right now is your usage of sprite.add. here is the syntax:
sprite.add( spriteSet, sequenceName, startFrame, frameCount, time, [loopParam] )
notice that it is startFrame, frameCount NOT startFrame, endFrame.
[import]uid: 21331 topic_id: 24353 reply_id: 98634[/import]
Ya, that’s your problem. Next time, I can help quicker if you use images, dropbox 'em. Sorry, didn’t notice sooner. [import]uid: 21331 topic_id: 24353 reply_id: 98635[/import]
I’ve changed it and now it works great! Thanks for you help! [import]uid: 116264 topic_id: 24353 reply_id: 98637[/import]
Most Welcome.
[import]uid: 21331 topic_id: 24353 reply_id: 98642[/import]
Great stuff Tony, as always!
Glad to see this got resolved; the frame count not frame number thing has tripped me up SO many times it’s embarrassing
[import]uid: 52491 topic_id: 24353 reply_id: 98696[/import]