spritekit
DESCRIPTION
An overview of SpriteKit, Apple's framework for 2d physics and animation.TRANSCRIPT
Michael Burks [email protected]
1. BattleBats 2. SpriteKit Overview 3. Pros & Cons 4. Performance Tips
Michael Burks [email protected]
BattleBats
• From concept to app in 8 weeks
• Multiplayer version of a classic arcade game
• includes an editor for users to create and share their own levels
• made entirely with SpriteKit!
Michael Burks [email protected]
SpriteKit Basics
• SKView presents SKScene
• SKScene contains SKNodes
Michael Burks [email protected]
SKNodes • SKSpriteNode!
• SKVideoNode!
• SKLabelNode!
• SKShapeNode!
• SKEmitterNode!
• SKCropNode!
• SKEffectNode
Michael Burks [email protected]
SKActions• are performed by SKNodes
• can do geometric transformations on SKNodes
• can modify attributes of SKNodes
• can play sounds
• can run custom blocks
• can be combined into groups, sequences, and repetitions
Michael Burks [email protected]
Physics!
• SKScene has an SKPhysicsWorld
• SKNodes can have SKPhysicsBodies
• SKPhysicsJoints can connect SKPhysicsBodies
Michael Burks [email protected]
SKPhysicsWorld
• controls (constant linear) gravity
• has methods to find SKPhysicsBodies at a point, in a rect, or along a ray
• sends its delegate didBeginContact: and didEndContact: methods
Michael Burks [email protected]
SKPhysicsBody• is created with a shape
• has area, mass, density
• has friction, restitution, damping
• has velocity, angular velocity
• has bit masks for contact and collision categories
• has methods to apply forces, impulses, and torques
Michael Burks [email protected]
SKPhysicsJoint
• SKPhysicsJointFixed
• SKPhysicsJointPin
• SKPhysicsJointSliding
• SKPhysicsJointLimit
• SKPhysicsJointSpring
Michael Burks [email protected]
SpriteKit Run Cycle• The scene calls its update: method.
• The scene executes actions on its children, then calls its didEvaluateActions method.
• The SKPhysicsContactDelegate methods didBeginContact: and didEndContact: are called if appropriate.
• The scene executes physics simulation on its physics bodies, then calls its didSimulatePhysics method.
Michael Burks [email protected]
Pros
• It’s easy and fun! You can quickly turn a concept into a prototype.
• It has everything you need - animation, physics, and collision detection.
• It looks good and works well.
Michael Burks [email protected]
Cons• SKNodes are subclasses of UIResponder,
not UIView. No gesture recognizers or UIControls in an SKScene or SKNode.
• The background color of an SKScene is opaque.
• SKLabelNodes only display a single line of text.
• No built-in system for Newtonian inverse-square gravity.
Michael Burks [email protected]
Cons• Running SKActions on SKNodes that are already
running SKActions can lead to unexpected results.
• Elastic collisions aren’t always elastic.
• No visualization of SKPhysicsJoints.
• No simple way to set the equilibrium length of SKPhysicsJointSpring.
• Changing the position of an SKNode doesn’t always register immediately with its associated SKPhysicsJoints.
Michael Burks [email protected]
Tips
• Apple has done the most to optimize these.
• They are MUCH faster than SKShapeNodes.
1. Use SKSpriteNodes!
Michael Burks [email protected]
Tips
• This helps you keep track of where SKNodes lie in the scene relative to each other.
• This can also help the SKView optimize drawing. Set the ignoresSiblingOrder property of the SKView to YES (new to beta 6).
2. Use the zPosition property to order SKNodes!