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.)
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.
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.
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.
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.
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.
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.