Another terror - Bats!

We are getting into quite a rhythm with creating new classes. Now, we will add a Bat to swarm with the Bees. The Bat is small, but has a very sharp fang:

Another terror - Bats!

Adding the Bat class

To add the Bat class, create a file named Bat.swift and add this code:

import SpriteKit class Bat: SKSpriteNode, GameSprite { var initialSize = CGSize(width: 44, height: 24) var textureAtlas: SKTextureAtlas = SKTextureAtlas(named: "Enemies") Var flyAnimation = SKAction() init() { super.init(texture: nil, color: .clear, size: initialSize) self.physicsBody = SKPhysicsBody(circleOfRadius: size.width / 2) self.physicsBody?.affectedByGravity = false createAnimations() ...

Get Swift Game Development - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.