Tuesday 17 June 2014

iOS Sprite Kit Game (Luke's Paddle Tree Game)

Activities @ Lynda - 




Screen Recording in iPhone Simulator


iOS Game Dev with Sprite Kit with Simon Allardice 
    (thanks Lynda for an awesome course!!) DONE
Screenshots of My First Game (Adapted from Copyright Lynda.com Tutorial)
  • GitHub Link: Luke's Breaking Bricks iOS Sprite Kit Game
  • Instructions: 
    • Touch and hold the bottom Paddle to play and prevent it falling. 
    • Move left and right to stop the ball hitting the bottom. 
    • Pause feature activates if you let go of paddle! Touch again to Unpause.
    • Destroy upper bricks to cause Tree to fall down. 
    • Win if Tree touches bottom of screen (tough luck if you deflect it elsewhere haha)
    • Lose if bottom Paddle or Ball touches bottom of screen.
    • Note: The paddle rapidly impulses automatically, so the ball is propelled faster with each contact with the paddle (brace yourself!)
    • Note: Win screen Screenshot not shown (you have to Win to see it!!!), Audio for winning was prepared by yours truly :)
  • Wondering how I preparing the game? It took under 2 days to prepare this game. The purpose of preparing it was to learn iOS Sprite Kit fundamentals programming in Objective-C using Xcode. Most of the code used to prepare the game came from following the Lynda.com course video. I added the following extensions to the game of my own in order to test the framework, but I expended minimal effort in doing so:
    • Custom background (simply a few random coloured brush strokes in Photoshop)
    • Custom sounds (silly 'You Win' and 'You Lose' sounds recorded using Quicktime Player)
    • Custom particle effects (simply replaced the particle effect snow flakes with an image of my head and slightly modified the effect in Particle Effects Editor)
    • Pause feature that activates when use stops touching screen (adapted from this post on Stackoverflow.com). Pause deactivates when the user touches the screen again
    • Tree shaped and coloured object and an animation sequence associated with it. The animation sequence throws the tree it into the screen amongst the bricks at the start of each game. The animation helps it slowly wiggle out of them
    • 'You Win' screen which appears upon contact between the tree object and the bottom of screen (the user may need to destroy the bricks to make it fall)
    • Impulses are automatically applied to the paddle so when the user holds down on the paddle and moves it left and right, the paddle will rapidly spring up and down in this defensive approach, so that each time the ball bounces off the paddle the ball speed increases, which in turn rapidly increases the game difficulty so you can fail or win fast and often! Alternatively an offensive approach can be taken during gameplay if the user chooses to simply hold down on the paddle but does not move left or right, as this will cause the paddle to only rise upward toward the bricks (until the user moves their touch left or right again)
    • If you'd like to know more, please feel free to contact me! Please ensure that you appropriately credit me and the sources I used if you share.

Game Elements 
Scenes (Architecture)
  • Node Types (Sprite, Label, Video, Shape, Emitter, Crop, Effect, etc) 
  • Node Use (manipulable independent Visual Elements Creation and Artwork, Property Configuration, Scene Inclusion, Manipulation, Drawing Order), FPS 
  • Node Association and Inheritance
  • Node Positioning and Coordinate System
    • Anchor Points of Scene and Nodes (Default to Parent Scene)
    • CGPoint (Core Graphics framework) (Explicit and Inline Creation)
  • Physics World (connect and configure different Scene {gravity, zero gravity} and Node Physics Body Properties
    • Physics Bodies (Volume-based (Default is Dynamic Volume or use Static) {simple Draw Path and Play-Testing for complex shapes to minimise Performance impact} , Edge-based). Each one has Bitmask Properties
      • categoryBitMask (Turned On by Default, each Physics Body can belong to multiple Categories and belong to all by Default)
      • collisionBitMask (Turned On by Default, cross-references all Categories where Physics Body should Register a Collision and provide notification of an event)
      • contactBitMask (Turned Off by Default, cross-references all Categories where Physics Body should Register a Contact and provide notification of an event)
    • Physics Body Properties (Mass, Density, Friction {object resistance at collision}, Linear Damping {object resistance moving across space}, Restitution {object bounciness at collision 0 to 1.0f}, Angular Damping, Velocity, etc)
    • Vectors (Magnitude {Force, Impulse}, Direction)
    • Touch Events 
    • Flexibility (Rotation Orientation Compatibility)
    • Collisions (causes them to bounce on impact, and prevents intersection of objects)
    • Contact (apply manually with custom code to be informed when touch detected between objects and apply logic to event)
      • didBeginContact and didEndContact  (reacts to contact using SKPhysicsContactDelegate Protocol)
    • Categories (meaningful Groupings of objects Defined for association with different Physics Body Objects, where Bitmasks are used to describe the actions upon touch between objects of different Categories {inform us, allow or disallow cross-over, bounce, nothing}, 32 Categories allowed to be toggled)
      • Bitwise Operators for defining Multiple Constants for each Categories
    • Landscape Orientation
      • CMD + Right Arrow (in Simulator)
    • Rendering/Game Loop 
      • update method (called at beginning of every frame)
      • didEvaluationActions method (check modifications after Sprite Kit evaluates actions and before any nodes changed are rendered to frame)
      • didSimulatePhysics methods (check mods of Physics Simulation but before affected nodes rendered to screen)
    • Texture Atlases (Manage Artwork Assets for Higher Performance by Grouping images)
      • Animation by Iterating Multiple Images
  • Game Play
    • Scene Transitions (Transition to Second Scene, Win and Lose Scene, Restart First Scene)
    • Sound Effects (SKAction in CAF format)
    • Convert to CAF Format (i.e. M4A from QuickTime Player to CAF Format File)
    • Apple Audio File Convert Tool use by type at Command-Line: 
                /usr/bin/afconvert -f caff -d LEI16 {INPUT} {OUTPUT}
    • Particle Systems (use Small Image and repeat Multiple times)
    • Particle Emitter controls effects under defined Particle Effect Rules using transitioning and Particle Emitter Inheritance to link gradually between nodes
    • Particle Emitter Editor (alternative to creating and setting properties of emitter node object with SKEmitterNode in code, instead simply define properties and save to SKS File for use to create Emitter Nodes)
    • iOS > New File > Resources > Sprite Kit Particle File
    • Actions (SKAction Class)
      • Methods with Reversible Actions
      • Combinations of Sequencing, Grouping, and Repeating Actions
      • Wait Action
  • Refactor 
    • Select Code Snippet > Right Click > Refactor > Extract 
Purchases:
Challenges:
  • Overcoming error "The model used to open the store is incompatible with the one used to create the store”?". 
    • Solution: Delete the SQL file in the apps documents directory
  • Display SQL syntax in Xcode Debugging Area
    • Solution: 
Menu > Product > Scheme > Edit Scheme > Arguments  "-com.apple.CoreData.SQLDebug 1"
  • Discovered how to overcome app always crashing (lost so much time trying to work this out) when attempting to save enum data to core data persistent store. I simply followed this Stackoverflow post from Paras Joshi to reset session and cache data in iPhone Simulator. Absolute lifesaver, this is now my favourite Xcode feature (how sad)!
         Menu > iOS Simulator > Reset Content and Settings

No comments:

Post a Comment