Hello,
this is my first post in this forum, so please bear with me 
Situation
- I’m working on a game viewed from top where ball bounces on individual platforms within defined platform field
- The goal of each level is to reach the end platform
- The field is scrolling from top to bottom of the screen
- There are gaps in the platform field
- When the ball jumps into the gap the game ends
- When the ball reaches left/right side of the screen, the platform fields scrolls till its left/right end is reached
- Mockup for better understanding (yellow platform is the end platform, green one is the one where the ball starts)
Problem
How do I detect that the ball hit some platform when it “hit the ground” (or that it hit the gap)?.
The fact that “hit the ground” event occurred is recognized via specific boolean flag that is set to true when onComplete callback in transition simulating the bounce effect (scaleX, scaleY to 1.x and then back to 1) is executed.
My solution ideas so far
All my ideas are based on the fact that I need to find index into table containing the platform objects. Then, I need to check if there is a platform with such index or if there is a gap, and decide what the correct action is - jump further or fall through.
Calculate platform index from ball coords when hit the ground occurs
My original idea was to calculate the index (into table containing the platform objects) of the platform that was hit from the coordinates of the ball when he hit the ground. This works when the field isn’t scrolling. However, when the field starts to scroll from top to bottom (and possibly also to left/to right), it is hard to calculate the right index.
Brute-force approach
Other option is to go through the whole table of platforms when the “hit the ground” event occurs, and perform some kind of hit test based on coordinates of the platform and ball. However, this doesn’t seem to be an efficient approach to me.
Use physics for pre-selection of possible platforms and hit test only those
I think that the Corona’s physics engine isn’t able to recognize collisions when the ball “falls” on the platform. However, it can register collision when the ball enters/leaves the platform (even when not “on the ground”) via normal collision mechanism and setting the physics bodies to be sensors. In such case, I can store the indexes of platforms which were involved into collision during one “bounce cycle” and then perform the “hit test” operation only on those. In next bounce cycle I create new list of possible “hit test” candidates, etc.
Your opinions
Any ideas for better / more effective solution? [import]uid: 164599 topic_id: 28701 reply_id: 328701[/import]
