DEV Community

Cover image for #100DaysOfSwift: Project 17
KeeyboardKeda
KeeyboardKeda

Posted on

#100DaysOfSwift: Project 17

Project 17 was a game in space where the user has to avoid objects coming their way.

Key Takeaways:

  1. SKEmitterNode was used to set the background image of space with star particles. SKSpriteNode was used to display the player's spaceship image. SKLabelNode was used as the score label.

  2. advanceSimulationTime() was used to give the effect of the star particles filling up the screen. This is a method of the emitter where you can simulate 10 seconds passing in the emitter and it will update the particles as if they were created 10 seconds ago.

  3. Per-pixel collision detection is used when images you want to use are an irregular shape. The collisions are based on actual pixels from one object touching actual pixels in another.

  4. Timer is used to run code after a period of time has passed, either once or repeatedly and it has five parameters:

    1. timeInterval: how many seconds you want the delay to be
    2. target: what object should be told when the timer starts
    3. selector: what method should be called on the object when the timer starts
    4. userInfo: any context you want to provide
    5. repeats: whether time should repeat
  5. linearDamping was used to make the objects the user has to avoid in space consistently move across the screen. angularDamping was used to make the objects consistently rotate. They are both added to the physicsBody and set to zero.

Top comments (0)