Hi all,
This is my first attempt at a SpriteKit project and Swift so please bear with me.
I have a SpriteKit scene and I've added a sprite with a Custom Class 'Player', which subclasses SKSpriteNode. In my scene swift file I am trying to call the Player setup function but when I run the project I get the error "Could not cast value of type 'SKSpriteNode' to MyAppName.Player"
Here is the following code I'm using, nothing major at the moment:
Level.swift
import SpriteKit
class LevelOne: SKScene {
var thePlayer:Player = Player()
override func didMoveToView(view: SKView) {
if (self.childNodeWithName("Player") != nil) {
thePlayer = self.childNodeWithName("Player") as! Player
thePlayer.setupPlayer()
}
}
... etc
Player.swift
import Foundation
import SpriteKit
class Player: SKSpriteNode {
func setupPlayer() {
print("this actually ran")
}
}
I've named my sprite 'Player' and added 'Player' as my Custom Class for the Sprite, but I get the can't cast error.
I'm using xCode 7.1.1 and I've also tried in 7.2 beta but still the same. I'm building in tvOS. I have an example project from a lesson which works and I've compared everything and there is no difference. I've looked at Targets and everything has been added as a Target to my project.
Any thoughts?
Regards
Paul