Help on expanding BalloonTap initial program - shift text, apply "hold touch" command

Hi, I am modifying the initial BalloonTap program in order to better understand how Cortana works in order to make my own game app. I have tried to read the lists of commands but haven’t found what I thought I wanted.

Question one:

I want the balloon to hold still when I click-and-hold it. I can’t find the Event that will allow me to write the code. Nor can I find the Physics command that will make it hold still.

This is what I have so far:

local function holdBalloon()
    balloon:applyForce( 0, 1, balloon.x, balloon.y)
end

balloon:addEventListener( “touch”, holdBalloon )

I don’t know how to make it differentiate between ‘touch’ and ‘tap’. What’s the difference? IS there a ‘hold’ type event at all?

Question two:

So, I added the text that counts the number of taps. Fine. I want it to be on the bottom (in the ‘ground’ bar) rather than in the sky. What do I change to do that? (My ‘ground’ image is a) right at the bottom of the screen and B) 50 px high.)

My code as is:

local tapText = display.newText( tapCount, display.contentCenterX, 20, native.systemFont, 40 )
tapText:setFillColor( 0, 0, 0)

Do I add something to do with display.contentHeightY??

I realise that this would have to go AFTER the ‘platform’ block to be viewed over the top of it.

Hope someone can give me some tips. Thanks!

I assume that you are referring to this tutorial?

For question 1:
You can find out about the differences and detailed sample code at https://docs.coronalabs.com/guide/events/touchMultitouch/index.html. Simply put, tap and touch are two different events. Tap has only one event phase for when the screen is tapped, whereas touch has several event phases for when the touch begins, when the user drags their finger (or mouse) on the screen and when they let go.

Sounds like touch event phase “moved” is the hold that you want. If you use touch event like this, then you’d then need to move the applyForce and tap counting to the “ended” phase.

For question 2:
 

local tapText = display.newText( tapCount, display.contentCenterX, display.actualContentHeight-20, native.systemFont, 40 ) tapText:setFillColor( 0 )

The following code will place your tapText to the very bottom of the screen (for all devices) and then shift it back up by 20 pixels. So yeah, by using display.actualContentHeight you can anchor things easily to the bottom.

The tutorial doesn’t seem to describe how to use display groups yet (seems that you learn about them in chapter 2). If you don’t use display groups, then the objects will appear so that the newest object always being placed in front of everything else.

Thanks XeduR!

I now think I understand the phases of ‘touch’ event. However, I’m still not certain how to apply the physics to make the balloon hold still.

I’m trying to find more tutorials, seems there were more than one chapter!

Stopping the physics really depends on what kind of game you are planning on creating. You can pause the physics engine by using physics.pause(). If you want to only stop a single object, then there are several approaches. One approach is setting the object’s gravityScale to 0 and setting it’s linearVelocity to (0,0). You’d have to reset the gravityScale after the touch ends.

This method will really only work if you don’t have other objects in the area that might collide with it. Alternatively you could also remove the physicsBody during touch and recreate it again afterwards. If you have other objects in the area that may collide with it, you’d probably want to create a temporary static physics body, etc.

You can google those terms and you’ll find the documentation for them. Corona’s documentation is really good and will answer most questions.

I assume that you are referring to this tutorial?

For question 1:
You can find out about the differences and detailed sample code at https://docs.coronalabs.com/guide/events/touchMultitouch/index.html. Simply put, tap and touch are two different events. Tap has only one event phase for when the screen is tapped, whereas touch has several event phases for when the touch begins, when the user drags their finger (or mouse) on the screen and when they let go.

Sounds like touch event phase “moved” is the hold that you want. If you use touch event like this, then you’d then need to move the applyForce and tap counting to the “ended” phase.

For question 2:
 

local tapText = display.newText( tapCount, display.contentCenterX, display.actualContentHeight-20, native.systemFont, 40 ) tapText:setFillColor( 0 )

The following code will place your tapText to the very bottom of the screen (for all devices) and then shift it back up by 20 pixels. So yeah, by using display.actualContentHeight you can anchor things easily to the bottom.

The tutorial doesn’t seem to describe how to use display groups yet (seems that you learn about them in chapter 2). If you don’t use display groups, then the objects will appear so that the newest object always being placed in front of everything else.

Thanks XeduR!

I now think I understand the phases of ‘touch’ event. However, I’m still not certain how to apply the physics to make the balloon hold still.

I’m trying to find more tutorials, seems there were more than one chapter!

Stopping the physics really depends on what kind of game you are planning on creating. You can pause the physics engine by using physics.pause(). If you want to only stop a single object, then there are several approaches. One approach is setting the object’s gravityScale to 0 and setting it’s linearVelocity to (0,0). You’d have to reset the gravityScale after the touch ends.

This method will really only work if you don’t have other objects in the area that might collide with it. Alternatively you could also remove the physicsBody during touch and recreate it again afterwards. If you have other objects in the area that may collide with it, you’d probably want to create a temporary static physics body, etc.

You can google those terms and you’ll find the documentation for them. Corona’s documentation is really good and will answer most questions.