Corona SDK - Touching 2 different buttons together
I'm trying to create an object moving using left and right navigation
arrow and making it shoot by press on is shoot button. But when I tried on
my phone, it doesn't allow me to press the navigation arrow and shoot at
the same time.
I can only navigate first then shoot. Meaning that only one touch action
at a time. How do I make it so that it can move and shoot at the same
time? Below is my code.
-- set motion and speed for characters
charMotionx = 0
speed = 2
local character = display.newImage("character.png")
local charLeftArrow = display.newImage("blue_left_nav.png")
local charRightArrow = display.newImage("blue_left_nav.png")
-- character movement
function charLeftArrow:touch()
charMotionx = -speed
end
function charRightArrow:touch()
charMotionx = speed
end
charLeftArrow:addEventListener("touch", charLeftArrow)
charRightArrow:addEventListener("touch", charRightArrow)
local function moveChar(event)
-- check moving infront or backwards
-- if moving infront
if (charMotionx ~= 0) then
character.moving = true
character:prepare("walking")
character:play()
end
if (charMotionx > 0) then
-- face right side when moving
character.xScale = 1
-- make sure doesn't move beyond front screen
if (character.x < (display.contentWidth * 0.81)) then
character.x = character.x + charMotionx
end
elseif (charMotionx < 0) then
-- face left side when moving
character.xScale = -1
-- if move backwards
-- cannot move beyond back screen
if (character.x > (display.contentWidth * 0.09)) then
character.x = character.x + charMotionx
end
end
end
Runtime:addEventListener("enterFrame",moveChar)
function shoot(event)
-- shoot action here
end
character.shoot = display.newImage("shoot.png")
character.shoot:addEventListener("touch",shoot)
No comments:
Post a Comment