Tap Anywhere

Hi All,

I have been following this tutorial for my game, https://www.youtube.com/watch?v=qEMGcy-mizM, and had a quick question regarding it.

In the tutorial you tap on the balloon and it goes up, then falls down.  I have all of that working fine, but would like to make a modification to it.  Basically, I would like to have it so that when the user taps anywhere on the screen the object will go up (rather than just taping the object), after a player taps once on the screen to start the game (tap once, game starts, tap again object moves; rather than having a play button).

If anybody knows of a method to do this, or point me in the right direction to find documentation on this it would be much appreciated.

Thanks :slight_smile:

The easiest form is create a global listener:

local function onTap() print("Tapped!") end Runtime:addEventListener( "tap", onTap )

Instead of only listening to taps on the balloon we will now listen always when a tap occurs.

Best regards,

Tomas

[quote name=“tomaswesterlund” post=“307465” timestamp=“1443302054”]The easiest form is create a global listener:

local function onTap() print("Tapped!") end Runtime:addEventListener( "tap", onTap )

Instead of only listening to taps on the balloon we will now listen always when a tap occurs.   Best regards, Tomas[/quote] Thank you so much, I really appreciate it. I just have one more question, using the same onTap methd for the whole screen, how could I make it so that the first tap triggers the start game, then the ones after that trigger the balloon until the game is over and resets, where the first tap would again reset the ballooms. Thanks!

Hey so a quick code put together here

local function balloonUp(event) if event.phase == "began" then print("tapStarted") elseif event.phase == "ended" then print("tapEnded") end local function startGame(event) if event.phase == "began" then print("tapStarted") -- Start the game here elseif event.phase == "ended" then print("tapEnded") -- add the eventListener for the ballon function here Runtime:addEventListener( "touch", balloonUp) end Runtime:addEventListener( "touch", startGame )

Im in a big hurry but ill be back in 2 hoursish so i could help then 

Good Luck!

wutt such a simple solution… For my game what I did was way too complicated. I made a transparent image in Photoshop the size of the whole screen, then added it as a display object. Since it’s transparent, it didn’t interfere with any other display/physics objects. Then added a touch listener to it. Haha I guss all that for nothing and all I needed was a Runtime touch listener. 

Haha, Well we all had to learn somehow!! So did you get everything working?

Yes, Sonic. App is ready. Just final tweaks and obviously still need to finalize the build, FB plugin and maybe iAds.

I haven’t seen the app butnid recommend you make really good graphics if you haven’t already…?

Good Luck!

Umm, well it’s okay quality graphics, not great. First ever app can’t really go crazy here haha. On phones it looks great. On tablets not so great. But phones are of course the priority. 

Thank you.

If that is the problem you might wanna check these two links:

https://docs.coronalabs.com/api/library/display/newImageRect.html

https://coronalabs.com/tutorials/developing-for-ipad-retina-display/

You need to have different sizes of the same image for different resolutions otherwise the high resolution devices (such as tablets) will use the low resolution images.

Best regards,

Tomas

wow I wasn’t even aware you could do that. This is great. Thanks a lot Tomas. I will definitely try to implement them as I go.

Hi,

Sorry for such the late reply.

I tried out the code and had a few questions on it.

Where you have “-- Start the game here”, would I put in my game function code (entire game), or can I reference it to an area below that? Would that be the code to make the balloon up, then just put the Runtime:addEventListener below where you have “-- add the eventListener for the balloon function here”?

Thanks.

So the startGame function is at the bottom and the whole game is above it… and when the startGame function is called then you add timers and listeners and all to the functions above… 

Good Luck!

The easiest form is create a global listener:

local function onTap() print("Tapped!") end Runtime:addEventListener( "tap", onTap )

Instead of only listening to taps on the balloon we will now listen always when a tap occurs.

Best regards,

Tomas

[quote name=“tomaswesterlund” post=“307465” timestamp=“1443302054”]The easiest form is create a global listener:

local function onTap() print("Tapped!") end Runtime:addEventListener( "tap", onTap )

Instead of only listening to taps on the balloon we will now listen always when a tap occurs.   Best regards, Tomas[/quote] Thank you so much, I really appreciate it. I just have one more question, using the same onTap methd for the whole screen, how could I make it so that the first tap triggers the start game, then the ones after that trigger the balloon until the game is over and resets, where the first tap would again reset the ballooms. Thanks!

Hey so a quick code put together here

local function balloonUp(event) if event.phase == "began" then print("tapStarted") elseif event.phase == "ended" then print("tapEnded") end local function startGame(event) if event.phase == "began" then print("tapStarted") -- Start the game here elseif event.phase == "ended" then print("tapEnded") -- add the eventListener for the ballon function here Runtime:addEventListener( "touch", balloonUp) end Runtime:addEventListener( "touch", startGame )

Im in a big hurry but ill be back in 2 hoursish so i could help then 

Good Luck!

wutt such a simple solution… For my game what I did was way too complicated. I made a transparent image in Photoshop the size of the whole screen, then added it as a display object. Since it’s transparent, it didn’t interfere with any other display/physics objects. Then added a touch listener to it. Haha I guss all that for nothing and all I needed was a Runtime touch listener. 

Haha, Well we all had to learn somehow!! So did you get everything working?

Yes, Sonic. App is ready. Just final tweaks and obviously still need to finalize the build, FB plugin and maybe iAds.

I haven’t seen the app butnid recommend you make really good graphics if you haven’t already…?

Good Luck!