Heyo!
I'm starting to create games on iOS and I'm trying a Breakout-clone for start. As practice I wanted a ball to bounce around in a rectangle so I get my head around simple collision, direction and velocity.
My ball got the following:
Point position; // x, y
float direction;
float velocity;
In my "u开发者_高级运维pdate" function, I want to move the ball in the current direction. What is the next position considering the velocity and direction?
Are there any helpers in some built-in frameworks in iOS?
I would really like to learn more about 2D-math so if someone got some reasources I would really appreciate if you send me a link.
What is the next position considering the velocity and direction?
Note that velocity already has direction; it is a vector
Bearing that in mind, your new position is:
position = CGPointMake(position.x + velocity.x, position.y + velocity.y)
Make velocity a CGPoint and make your direction variable redundant.
Convert the direction and velocity into a vector, scale it for time, and then add it to the current position, accounting for obstacles encountered along the path.
精彩评论