Game Development Reference
In-Depth Information
}
-(void) ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event
{
fingerLocation = [Helper locationFromTouch:touch];
}
-(void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
moveToFinger = NO;
}
These methods specify that while a finger is touching the screen, the ball moves toward
the finger; and while the finger is moving, the fingerLocation is constantly up-
dated.
Next, take a quick look at the update method of the Ball class:
-(void) update:(ccTime)delta
{
if (moveToFinger == YES)
{
[self applyForceTowardsFinger];
}
if (sprite.position.y < -(sprite.contentSize.height * 10))
{
[self setBallStartPosition];
}
// limit speed of the ball
const float32 maxSpeed = 6.0f;
b2Vec2 velocity = physicsBody- > GetLinearVelocity();
float32 speed = velocity.Length();
if (speed > maxSpeed)
{
velocity.Normalize();
physicsBody- > SetLinearVelocity(maxSpeed * velocity);
}
Search Nedrilad ::




Custom Search