0
私のプログラムでは、異なるテクスチャを持つ2つの異なる種類のピースを同じクラスのクラスに作成しようとしています。クラスのテクスチャは変更されますが、表示されません
このクラスはサブクラスなので、super.initのテクスチャをデフォルトのテクスチャに設定する必要があります。私はテクスチャを変更しますが、プログラムの実行時にデフォルトのテクスチャだけが表示されます。
テクスチャを印刷しようとしましたが、テクスチャが変更されています。何が起こっている?
注:私はスタンドとしてのチェッカーピースを使用しています。赤いチェッカーピースは1つのスタンド(赤いチームのスタンド)です。画像は、ここでは黒チェッカー片
を表示すべき問題である。
ここでプリントアウトです。ここで
産卵のためとライフルマンクラスのコードです:
func spawnBlueRiflemen(at: CGPoint) {
let newBlueRifle = rifleman()
newBlueRifle.texture = textureBlueRifle
newBlueRifle.position = at
newBlueRifle.team = "Blue"
print("\(newBlueRifle.texture)")
self.addChild(newBlueRifle)
}
class rifleman: Character, pTargetable{
var health = 10
init() {
super.init(tag: 0, team: "generic", currentAction: 0, texture: textureRedRifle)
var xSize = texture.size().width // Create The texture for the top (visible sprite)
var ySize = texture.size().height
var size = CGSize(width: xSize, height: ySize)
self.physicsBody = SKPhysicsBody(texture: texture, size: size)
self.physicsBody?.isDynamic = false
self.physicsBody?.affectedByGravity = false // (physical body stuff)
self.physicsBody?.mass = 1.0
self.name = "\(tag)"
var top = SKSpriteNode(texture: texture, size: size)
top.zPosition = layers.characters
top.color = SKColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
top.colorBlendFactor = 1.0
self.addChild(top)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func takeDamage(damage: Int) {
health -= damage
print("\(tag) lost \(damage) hit points")
if health <= 0 {
die()
print("\(tag) is dead now")
}
}
}