我正在开发我的游戏一切似乎都很好,但我不断收到此错误消息 这是错误所在的代码段。玩家是一个班级
player = Player(node: player, particles: playerParticles!)
func addPlayer() {
var player = SKSpriteNode(imageNamed: "player.png")
player.physicsBody = SKPhysicsBody(texture: player.texture!, size: player.size)
player.physicsBody!.affectedByGravity = false
player.physicsBody!.allowsRotation = false
player.physicsBody!.categoryBitMask = ColliderType.Plyer.rawValue //sets value to 1
player.physicsBody!.contactTestBitMask = ColliderType.Enemy.rawValue //will make contact with any value 2
player.physicsBody!.collisionBitMask = ColliderType.Enemy.rawValue //will collide with any value 2
let playerParticles = SKEmitterNode(fileNamed: "")
playerParticles?.isHidden = true
player = Player(node: player, particles: playerParticles!)
player.addChild(playerParticles!)
addChild(player)
以下是玩家类:
import Foundation
import SpriteKit
class Player {
var playerr:SKSpriteNode
var speed = 0.1
var showParticles = false
var particlesFrameCount = 0
var maxParticleFrames = 20
var particles:SKEmitterNode
init(node:SKSpriteNode, particles:SKEmitterNode) {
self.playerr = node
self.particles = particles
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
答案 0 :(得分:2)
尝试这样的事情
func addPlayer() {
var player = SKSpriteNode(imageNamed: "player.png")
player.physicsBody = SKPhysicsBody(texture: player.texture!, size: player.size)
player.physicsBody!.affectedByGravity = false
player.physicsBody!.allowsRotation = false
player.physicsBody!.categoryBitMask = ColliderType.Plyer.rawValue //sets value to 1
player.physicsBody!.contactTestBitMask = ColliderType.Enemy.rawValue //will make contact with any value 2
player.physicsBody!.collisionBitMask = ColliderType.Enemy.rawValue //will collide with any value 2
self.addChild(player)
let playerParticles = SKEmitterNode(fileNamed: "")
playerParticles?.isHidden = true
self.addChild(playerParticles)