Hello, everybody!
Pls help me a little, I am making a game wich have a line of balls, that must appear from right edge and move to left edge one by one, then they disapear out of screen.
I need to set the gap and quantity of balls in line (1 to 10).
I can hide 10 balls out of right edge of screen.
I can start 1st ball.
But I cant imagine how to start the other balls one by one (in course).
You could use a clock and set the timer to the appropriate value. Once the timer fires start the second ball, then the third, foruth and so on until all 10 are moving.
I need to use a gap in pixels but not in seconds.
For example
- Start Ball1
- When Ball1.X = (Screen.Width - Ball.Radius x 2 - Gap)
start Ball2.
Use some maths to work out how the distance between the balls, the speed the balls are travelling at and work out the time it takes for a ball to cross a gap.
Alternatively, create a ball that has no background colour and is stationary - it will be invisible to the user. Place it at the relevant position.
If Ball 1 radius is 5% of the canvas width and the gap is 10% of the canvas width then place it at (0.75 x canvas width).
When Ball 1 collides with it, start Ball 2’s motion.
When Ball 2 collides with it, start Ball 3’s motion, and so on.
The invisible ball’s right edge will be at 80% of the canvas width. When Ball 1 collides with it (assuming it’s radius is also 5% of canvas width) then it’s right edge will be at 90% of canvas width. Start Ball 2 at (canvas width x 1.05). This way Ball 2’s left edge will be at 100% of canvas width and so there will be a 10% gap between Ball 1’s right edge and Ball 2’s left edge.
The idea with invisible sprite is very good, I like it.
But how to do the following?
When Ball 1 collides with it, start Ball 2’s motion.
When Ball 2 collides with it, start Ball 3’s motion, and so on.
I guess it needs to use a list of balls?
For example we need to move only 5 balls.
Use the collide with block.
When Ball 1 collides with Invisible Ball, set Ball 2 speed to whatever you want.
Yes.
init global a list of Ball components.
For each round, take a copy of that list, and remove item 1 after it hits the left edge.
Then slide all the visible balls down and start the new item 1 moving.
Stop when your list is empty.