iOS Game Development Cookbook by Jonathon Manning and Paris Buttfield-Addison

iOS Game Development Cookbook by Jonathon Manning and Paris Buttfield-Addison

Author:Jonathon Manning and Paris Buttfield-Addison
Language: eng
Format: mobi, epub
ISBN: 9781449368760
Publisher: O’Reilly Media, Inc.
Published: 2014-03-31T16:00:00+00:00


Adding Physics to Sprites

Problem

You want to make sprites be affected by gravity and other physical forces.

Solution

To make an SKSpriteNode be physically simulated, create an SKPhysicsBody and then set the sprite’s physicsBody property to it:

SKScene* scene = ... // an SKScene SKSpriteNode* sprite = [SKSpriteNode spriteNodeWithColor:[SKColor whiteColor] size:CGSizeMake(100, 50)]; sprite.position = CGPointMake(CGRectGetMidX(scene.frame), CGRectGetMidY(scene.frame)); sprite.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:sprite.size]; [scene addChild:sprite];



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.