Hello,
i am building a shooter game and am trying to detect a multi touch event where the player can drag the sprite with none finger as well as shoot bullets with the other finger…i can;t seem to figure out how to use the touchID…
at the start of the class i activate the multitouch
system.activate(“multitouch”)
i then declare some variables
local alien
local bullet
local bg = display.newImage(“bg.png”)
bg:setReferencePoint(display.TopLeftReferencePoint)
bg:scale(10,10)
bg.x = -50
local bullets = display.newGroup()
as well as functions
local Main = {}
local addAlien = {}
local listeners = {}
local shoot = {}
local moveAlien = {}
local update = {}
the constructor and other functions:
function Main()
addAlien()
end
function addAlien()
alien = display.newImage(‘alien.png’)
alien:scale(0.5,0.5)
alien.x = display.contentCenterX
alien.y = display.contentCenterY
listeners(‘add’)
end
function listeners(action)
if(action == ‘add’) then
bg:addEventListener(‘touch’,moveAlien)
bg:addEventListener(‘touch’,shoot)
Runtime:addEventListener(‘enterFrame’,update)
else
bg:removeEventListener(‘touch’,moveAlien)
bg:removeEventListener(‘touch’,shoot)
Runtime:removeEventListener(‘enterFrame’,update)
end
end
and here is where i think the problem is:
function moveAlien:touch(e)
if(e.phase == ‘began’)then
display.getCurrentStage():setFocus(bg,e.id)
lastX = e.x - alien.x
lastY = e.y - alien.y
elseif(e.phase == ‘moved’)then
alien.x = e.x - lastX
alien.y = e.y - lastY
elseif(e.phase == ‘ended’)then
display.getCurrentStage():setFocus(nil)
end
end
here is the shoot function:
function shoot:touch(e)
if(e.phase == ‘began’)then
bullet = display.newImage(‘bullet.png’)
bullet:scale(0.2,0.2)
bullet.x = alien.x
bullet.y = alien.y-15
bullet.name = ‘bullet’
bullets.insert(bullets,bullet)
elseif(e.phase == ‘ended’) then
end
end
and the rest of the code:
function update(e)
if(bullets.numChildren ~= 0)then
for i = 1,bullets.numChildren do
if(bullets[i] ~= nil)then
bullets[i].x = bullets[i].x+10
end
end
end
end
----call main
Main()
any help would be appreciated,
thanks