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]