DEV Community

Cover image for #100DaysOfSwift: Project 14
KeeyboardKeda
KeeyboardKeda

Posted on

#100DaysOfSwift: Project 14

Hello !

For this project I created a Whack a Penguin game by using SpriteKit. GameScene.swift is where the layout of the game was created such as the holes the penguins will emerge from, and the score. A subclass of SKNode was created to hold all the functionality of the holes like when the penguin hides and is visible.

Key Takeaways:

  1. SKCropNode uses an image as a cropping mask where anything that is colored will be visible and anything in the transparent part will be invisible.

  2. The SKAction called moveBy:(x:,y:,duration) is used to move the penguin upwards and downwards out of the hole.

  3. The character node was added to the crop node and the crop node was added to the hole. This line of code (let whackSlot = node.parent?.parent as? WhackSlot) was needed because the player tapped the penguin sprite node and not the hole. This code gets the parent of the parent node and typecast it as a WhackSlot. SKCropNode only crops nodes that are placed inside of it.

  4. Objects are sorted by Z position, where higher numbers are placed on top of the lower numbers. For example, zPosition = - 1 would be behind zPosition = 1.

  5. Action sequences are in an array and execute in order, not at the same time.

Top comments (0)