I’ve been using Corona since the alpha builds of Game Edition (when sprites were still pretty buggy), so I got used to using movieclips, which probably isn’t the most efficient way to do things right now but it’s working fine for me so far.
With that said, keep in mind that the code below is using the movieclip library instead of spritesheets. So if you use spritesheets, just modify lines that are movieclip-specific to their spritesheet code counterparts:
To explain the code a little bit, in Dungeon Tap, I have a never-ending timer handle the switching of frames for the player’s animation. The code below is pasted directly from the Dungeon Tap source code:
[blockcode]
local playerAnimation = function()
if gameIsActive then
if playerObject.isJumping == false and playerObject.isFalling == false then
if playerObject.framePosition == “left” then
if playerObject.frameNumber == 1 then
playerObject:stopAtFrame( playerObject.startWalkLeft )
playerObject.frameNumber = 2
elseif playerObject.frameNumber == 2 then
playerObject:stopAtFrame( playerObject.endWalkLeft )
playerObject.frameNumber = 1
end
elseif playerObject.framePosition == “right” then
if playerObject.frameNumber == 1 then
playerObject:stopAtFrame( playerObject.startWalkRight )
playerObject.frameNumber = 2
elseif playerObject.frameNumber == 2 then
playerObject:stopAtFrame( playerObject.endWalkRight )
playerObject.frameNumber = 1
end
end
elseif playerObject.isFalling == true then
if playerObject.framePosition == “right” then
playerObject:stopAtFrame( playerObject.fallRightFrame )
elseif playerObject.framePosition == “left” then
playerObject:stopAtFrame( playerObject.fallLeftFrame )
end
end
end
end
playerObject.animTimer = timer.performWithDelay( 250, playerAnimation, 0 ) --> 250 is default interval
[/blockcode]
So the above code is what keeps the player’s animation and frames updated. Below is my onTilt() function (my accelerometer interval is set to 45.0):
[blockcode]
local onTilt = function( event )
if gameIsActive then
if event.xGravity > 0.01 then
playerObject.framePosition = “right”
elseif event.xGravity < -0.01 then
playerObject.framePosition = “left”
end
playerObject.x = playerObject.x + (playerObject.speed * event.xGravity)
end
end
[/blockcode]
Some of the code above is Dungeon Tap-specific, so that obviously won’t apply to your project, but the code above should give you an idea of how to accomplish the whole thing.
Hope that helps!
Jonathan Beebe
http://jonbeebe.tumblr.com/
http://beebegamesonline.appspot.com/ [import]uid: 7849 topic_id: 4104 reply_id: 12998[/import]