Applying velocity to a SKSpriteNode subclass & trouble with Expected Declaration Error <p>I'm currently working on my first iPhone game and I have a SKSpriteNode subclass <code>Alien</code> (which is also an abstract class) that will later be inherited by a class <code>normAlien</code>. Even with Apple's docs, I've been having a lot of trouble figuring out class initialization and inheritance in Swift. Here is the code for both classes:</p> <pre><code>//Generic alien type: a blue-print of sorts class Alien:SKSpriteNode{ static func normalizeVector(vector:CGVector) -&gt; CGVector{ let len = sqrt(vector.dx * vector.dx + vector.dy * vector.dy) return CGVector(dx:vector.dx / len, dy:vector.dy / len) } func motion(velocity:CGVector, multiplier:CGFloat){ //Alien.physicsBody?.velocity.dx = velocity.dx * multiplier //Why no work? self.physicsBody?.velocity.dx = velocity.dx * multiplier self.physicsBody?.velocity.dy = velocity.dy * multiplier } let velocityVector:CGVector let startPos:CGPoint init(texture:SKTexture, startPosition startPos:CGPoint,moveSpeed: CGFloat,velocityVector:CGVector){ self.velocityVector = Alien.normalizeVector(velocityVector) self.startPos = startPos //Makes sure the SKSpriteNode is initialized before modifying its properties super.init(texture: texture, color: UIColor.clearColor(), size: texture.size()) //PhysicsBody is a property of super so super.init must be called first (init SKSpriteNode) self.physicsBody? = SKPhysicsBody(circleOfRadius: self.size.width/2) self.physicsBody?.dynamic = true self.physicsBody?.categoryBitMask = PhysicsCategory.Alien //physicsBody?. is optional chaining? self.physicsBody?.collisionBitMask = 0 //Do I need this? or jsut use in laser class self.physicsBody?.contactTestBitMask = PhysicsCategory.Laser self.physicsBody?.usesPreciseCollisionDetection = true //Motion self.physicsBody?.velocity.dx = velocityVector.dx * moveSpeed self.physicsBody?.velocity.dy = velocityVector.dy * moveSpeed //self.velocityVector = normalizeVector(velocityVector) self.position = startPos } //Alien.motion(self.velocityVector, moveSpeed) required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } } </code></pre> <p>As well as:</p> <pre><code>class normAlien:Alien{ static let alienImage = SKTexture(imageNamed:"Sprites/alien.png") //alienImage.setScale(0.2) init(startPos:CGPoint,speed: CGFloat){ super.init(texture:normAlien.alienImage, startPosition: startPos, moveSpeed:speed,velocityVector:CGVector(dx: 1,dy: 0)) } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } } </code></pre> <p>I have a function: </p> <pre><code>func buildAlien(){ let aAlien = normAlien(startPos:CGPoint(x:0,y:size.height/2), speed:100) addChild(aAlien) } </code></pre> <p>that that instantiates <code>normAlien</code> within <code>didMoveToView</code> (This function is just called within a <code>SKAction.repeatActionForever</code>). For some reason each sprite created fails to move. I'm confused because they do move if I use a <code>SKAction.moveTo</code> so I must not understand something about applying velocity. </p> <p>On top of this, I'm confused as to why I receive the error: <code>Expected declaration</code>when I attempt to manipulate the <code>normAliens</code> texture with <code>alienImage.setScale(0.2)</code> and also when I try to call an internal method on the class: <code>Alien.motion(self.velocityVector, moveSpeed)</code>? I would think that calling this method inside the class would cause every instance I make to have it called- making them potentially move. </p> <p>Any help would be really appreciated.</p>