spritekit

21
BattleBats: A SpriteKit Game Michael Burks [email protected]

Upload: michael-burks

Post on 08-May-2015

656 views

Category:

Technology


3 download

DESCRIPTION

An overview of SpriteKit, Apple's framework for 2d physics and animation.

TRANSCRIPT

Page 1: SpriteKit

BattleBats: A SpriteKit Game

Michael Burks [email protected]

Page 2: SpriteKit

Michael Burks [email protected]

1. BattleBats 2. SpriteKit Overview 3. Pros & Cons 4. Performance Tips

Page 3: SpriteKit

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!

Page 5: SpriteKit

Michael Burks [email protected]

SpriteKit Basics

• SKView presents SKScene

• SKScene contains SKNodes

Page 6: SpriteKit

Michael Burks [email protected]

SKNodes • SKSpriteNode!

• SKVideoNode!

• SKLabelNode!

• SKShapeNode!

• SKEmitterNode!

• SKCropNode!

• SKEffectNode

Page 7: SpriteKit

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

Page 8: SpriteKit

Michael Burks [email protected]

Physics!

• SKScene has an SKPhysicsWorld

• SKNodes can have SKPhysicsBodies

• SKPhysicsJoints can connect SKPhysicsBodies

Page 9: SpriteKit

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

Page 10: SpriteKit

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

Page 11: SpriteKit

Michael Burks [email protected]

SKPhysicsJoint

• SKPhysicsJointFixed

• SKPhysicsJointPin

• SKPhysicsJointSliding

• SKPhysicsJointLimit

• SKPhysicsJointSpring

Page 12: SpriteKit

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.

Page 13: SpriteKit

Michael Burks [email protected]

Pros & Cons

Page 14: SpriteKit

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.

Page 15: SpriteKit

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.

Page 16: SpriteKit

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.

Page 17: SpriteKit

Michael Burks [email protected]

But hey...

Page 18: SpriteKit

Michael Burks [email protected]

Tips

• Apple has done the most to optimize these.

• They are MUCH faster than SKShapeNodes.

1. Use SKSpriteNodes!

Page 19: SpriteKit

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!

Page 20: SpriteKit

Michael Burks [email protected]

Go make SpriteKit apps! !

!

(if I can do it, you probably can too)

Page 21: SpriteKit

Michael Burks [email protected]

Questions?