我正在制作一款 RPG 类型的游戏,您可以在其中选择用户的攻击方式。我正在努力使我有一个名为“Projectile”的超类,其中描述了一般变量,以及更改变量的子类。但是每当我覆盖变量的值时,我都会得到一个 EXC_BAD_INSTRUCTION。
import Foundation
import SpriteKit
class Projectile: SKNode {
var texture: SKTexture!
var projectileBody = SKSpriteNode()
var projectile: SKEmitterNode!
var negativeEffect: DefaultNegativeEffect!
func setUpValues() {
texture = SKTexture(imageNamed: "bokeh.png")
projectileBody = SKSpriteNode()
projectile = SKEmitterNode(fileNamed: "testbokeh.sks")
negativeEffect = DefaultNegativeEffect(runningSpeed: 0)
}
override init() {
super.init()
projectileBody.texture = texture
projectileBody.size = texture.size()
projectileBody.position = self.position
self.physicsBody = SKPhysicsBody(circleOfRadius: 2)
self.physicsBody?.dynamic = true
self.physicsBody?.categoryBitMask = PhysicsCategory.Projectile
self.physicsBody?.contactTestBitMask = PhysicsCategory.Monster
self.physicsBody?.collisionBitMask = PhysicsCategory.None
self.physicsBody?.usesPreciseCollisionDetection = true
projectile.position = self.position
self.addChild(projectileBody)
self.addChild(projectile)
}
func update() {
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
import Foundation
import SpriteKit
class FireBall: Projectile {
override func setUpValues() {
texture = SKTexture(imageNamed: "spark5.png")
projectileBody = SKSpriteNode()
projectile = SKEmitterNode(fileNamed: "testbokeh.sks")
negativeEffect = DefaultNegativeEffect(runningSpeed: 0)
}
}