Nüb question about my jumping sprite

I’m new to Corona so sorry if this question seems rudimentary. My game style is top-down (as in overhead view), and involves the main character as an object that moves horizontally using the accelerometer, then jumping (somersaulting) into the air in order to dodge things.

I’m trying to get it so that when you touch anywhere on the screen the jumping animation occurs. I got it to work somewhat, but the character just stays in the middle of the screen where the original coordinates are. If you touch the screen once, it’s fine. But if you do it again, the jumping animation loops over and over again nonstop. Also, there ends up being two instances of the hero on screen.

Essentially, I’m trying to make it so that when you touch the screen, the still image of the character turns into an animated sprite, then back. Any help is appreciated!

Here is what I have so far. Would it be easier to use movieclip instead?
– Our hero sprite sheet
local herosheet = sprite.newSpriteSheet(“character.png”, 64, 72)

– Defining the sprite we’re going to be using
local heroset = sprite.newSpriteSet (herosheet, 1, 12)
sprite.add (heroset, “hero”, 6, 1, 300, 0)

– Giving the sprite a name (hero) and positioning it
local hero = sprite.newSprite (heroset)
hero.x = 160
hero.y = 160
localGroup:insert(hero)
– Sprite is ready to go!
–hero:prepare(“hero”)
–hero:play(“hero”)
–hero.isFixedRotation = true
– Note the radius is set to 10 to make collision look more realistic and accurate
physics.addBody(hero, “static”, {radius = 20})

–Defining the flip sprite
local flipSpriteSheet = sprite.newSpriteSheet(“character.png”, 64, 72)

local flipSet = sprite.newSpriteSet(flipSpriteSheet, 1, 12)
sprite.add(flipSet, “jump”, 1, 12, 300, 1)

local flipInstance = sprite.newSprite( flipSet )

flipInstance:prepare(“jump”)

local function onTouch(event)
if event.phase == “ended” then
flipInstance.x = hero.x
flipInstance.y = hero.y
audio.play(flipSound)
flipInstance:play()
end
end
Runtime:addEventListener(“touch”, onTouch) [import]uid: 68619 topic_id: 16888 reply_id: 316888[/import]

Wow… nobody??? I’m sorry if this question was asked before in so many different ways, but I really don’t know where else to turn.
[import]uid: 68619 topic_id: 16888 reply_id: 63631[/import]

Hi.

I think you are overcomplicating things. Why not add the static (non animated) sprite to your spritesheet and simply play that (once) when you need, as opposed to overcomplicating it by switching back and forth ? [import]uid: 84637 topic_id: 16888 reply_id: 63659[/import]

Hi Danny,
I tried something after digesting some of the other answers I found on here, and what I came up with is along the lines of what you’re suggesting. I even successfully made the character into a physics object. In my character’s movieclip, the first 4 frames are supposed to be the animation of the character running. Frames 5-12 are the jumping animation.

The jumping on touch function works fine, eg. it plays frames 5-12. But the running animation does not. It seems stuck on the same frame. Am I even using the “enterFrame” EventListener correctly in this case?


require “movieclip”

player = movieclip.newAnim{ “man_01.png”, “man_02.png”, “man_03.png”, “man_04.png”, “man_05.png”, “man_06.png”, “man_07.png”, “man_08.png”, “man_09.png”, “man_10.png”, “man_11.png”, “man_12.png” }
–player:play()
player.x=display.contentWidth/2
player.y=200

physics.addBody(player, “static”, {radius = 20})

function running(event)
if event.phase == “began” then
player:play{ startFrame=1, endFrame=4, loop=0, remove=false }
end
end
Runtime:addEventListener(“enterFrame”, running)

function jump(event)
if event.phase == “ended” then
player:play{ startFrame=5, endFrame=12, loop=1, remove=false }
end
end
Runtime:addEventListener(“touch”, jump)


Can you spot what might be wrong? Maybe the running and jumping can be a consolidated into a single function with an elseif/then statement?

Again, thanks for your help.
[import]uid: 68619 topic_id: 16888 reply_id: 63698[/import]