SpriteKit

1,129 views
920 views

Published on

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

Published in: Technology, Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,129
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
12
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

SpriteKit

  1. 1. BattleBats: A SpriteKit Game Michael Burks michael@radtastical.com
  2. 2. 1. BattleBats 2. SpriteKit Overview 3. Pros & Cons 4. Performance Tips Michael Burks michael@radtastical.com
  3. 3. 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 michael@radtastical.com
  4. 4. Demo Michael Burks michael@radtastical.com
  5. 5. SpriteKit Basics • SKView presents SKScene • SKScene contains SKNodes Michael Burks michael@radtastical.com
  6. 6. SKNodes • • • • • • • SKSpriteNode! SKVideoNode! SKLabelNode! SKShapeNode! SKEmitterNode! SKCropNode! SKEffectNode Michael Burks michael@radtastical.com
  7. 7. 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 michael@radtastical.com
  8. 8. Physics! • SKScene has an SKPhysicsWorld • SKNodes can have SKPhysicsBodies • SKPhysicsJoints can connect SKPhysicsBodies Michael Burks michael@radtastical.com
  9. 9. 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 michael@radtastical.com
  10. 10. 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 michael@radtastical.com
  11. 11. SKPhysicsJoint • SKPhysicsJointFixed • SKPhysicsJointPin • SKPhysicsJointSliding • SKPhysicsJointLimit • SKPhysicsJointSpring Michael Burks michael@radtastical.com
  12. 12. 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 michael@radtastical.com
  13. 13. Pros & Cons Michael Burks michael@radtastical.com
  14. 14. 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 michael@radtastical.com
  15. 15. 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 inversesquare gravity. Michael Burks michael@radtastical.com
  16. 16. 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 michael@radtastical.com
  17. 17. But hey... Michael Burks michael@radtastical.com
  18. 18. Tips 1. Use SKSpriteNodes! • Apple has done the most to optimize these. • They are MUCH faster than SKShapeNodes. Michael Burks michael@radtastical.com
  19. 19. Tips 2. Use the zPosition property to order SKNodes! • 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). Michael Burks michael@radtastical.com
  20. 20. Go make SpriteKit apps! ! ! (if I can do it, you probably can too) Michael Burks michael@radtastical.com
  21. 21. Questions? Michael Burks michael@radtastical.com

×