Game Development Reference
In-Depth Information
5. You can also apply impulse instead of force. Impulse can be defined as a force
that acts for a specific interval of time and is equal to the change in linear mo-
mentum produced over that interval.
[gameObject.physicsBody
applyImpulse:CGVectorMake(10.0f, -10.0f)];
6. While creating games, we frequently use static objects. To create a rectangular
static object we can use the following code:
SKSpriteNode* box = [[SKSpriteNode alloc]
initWithImageNamed: @"box.png"];
box.name = @"box_object";
box.position = CGPointMake(CGRectGetMidX(self.frame),
box.frame.size.height * 0.6f);
[self addChild:box];
box.physicsBody = [SKPhysicsBody
bodyWithRectangleOfSize:box.frame.size];
box.physicsBody.friction = 0.4f;
// make physicsBody static
box.physicsBody.dynamic = NO;
So all the code is the same except one special property, which is dynamic. By de-
fault this property is set to YES , which means that all the physics bodies will be
dynamic by default and can be converted to static after setting this Boolean to NO .
Static bodies do not react to any force or impulse. Simply put, dynamic physics
bodies can move while the static physics bodies cannot .
Search WWH ::




Custom Search