tap anywhere to shoot

Hi y’all,
What is the best way to do a ‘tap anywhere on device’ to shoot/spawn new objects?
I had the idea to have just an invisible object on top of all other objects covering the size of the device, but that seems like might create conflicts…not sure, haven’t tried it.

It doesn’t need to be a spawn items to where you ‘tap/touch’, but that will be cool.

If anyone has done it and/or has any tips, please share.

Thanks,
RD [import]uid: 7856 topic_id: 4880 reply_id: 304880[/import]

[lua]Runtime:addEventListener( “tap”, addBall )[/lua]

?? [import]uid: 6645 topic_id: 4880 reply_id: 15709[/import]

I don’t want to tap on ‘a ball’ or any other object, just on the device, so the main guy firing, just ‘spawns’ the bullet.
Does that make sense? [import]uid: 7856 topic_id: 4880 reply_id: 15712[/import]

that’s why i’ve put the event on the Runtime not an object [import]uid: 6645 topic_id: 4880 reply_id: 15714[/import]

ah… :wink: [import]uid: 7856 topic_id: 4880 reply_id: 15715[/import]

Just to clarify, what that code does is take you to the addball function whenever you tap on the screen. Then in the addball function (or whatever you wanna call it) you can define the action you want, like adding balls to the screen or shooting bullets. I hope that’s more clear.

Now I have a question of my own. What if I wanna do the same, but for a finger swipe? I also want to get the direction. Think firing a beam on the direction and angle of the swipe. [import]uid: 10835 topic_id: 4880 reply_id: 15716[/import]

for a swipe you’d want to use the “touch” event… then check the distance/angle/speed differences in between your “began”, “moved” and “ended” phases and calculate the gesture based on those values, using a bit of trig

this might help
http://developer.anscamobile.com/code/samurai-kitchen

[import]uid: 6645 topic_id: 4880 reply_id: 15718[/import]

[lua]-- the slice event
local function onTouch( event )
local t = event.target

local phase = event.phase

local x,y = t:localToContent( t.x - t.xOrigin, t.y - t.yOrigin )
local dx = event.x - x
local dy = event.y - y
local angle = math.atan2( dy, dx )

if “began” == phase then
display.getCurrentStage():setFocus( t )
t.isFocus = true
t.xStart = t.x
t.yStart = t.y
t.angleStart = angle
t.rotationStart = t.rotation
elseif t.isFocus then
if “moved” == phase then
local pi = math.pi
local delta = (angle - t.angleStart)
delta = delta*180/pi
t.rotation = t.rotationStart + delta
if ((xpos > 140) and (xpos < 180)) then
if ((t.rotation < -40) and (t.rotation > -60)) then
suspendGame();
isSliced = true;
timer.performWithDelay( 1500, resetPos,1);
end
end

elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil )
t.isFocus = false
t.rotation = kStartAngle
local coord = t.x … “,” … t.y
end
end
return true
end[/lua] [import]uid: 6645 topic_id: 4880 reply_id: 15720[/import]

Samurai Kitchen doesn’t work for me, I think maybe it no longer works in the latest version of Corona.

Anyway, the method he described is the way to go. To elaborate on what he suggested, the “began” and “ended” positions are all you need to use to calculate the angle and distance of the swipe, but you want to check to make sure the angle is pretty constant every “move” event to make sure the player isn’t doing a loop gesture or something. [import]uid: 12108 topic_id: 4880 reply_id: 15742[/import]

did you read the article? they posted a fix due to the changes in the new API. [import]uid: 6645 topic_id: 4880 reply_id: 15747[/import]

oh no I haven’t seen that, thanks for pointing it out. [import]uid: 12108 topic_id: 4880 reply_id: 15753[/import]