在我正在制作的程序中,我试图有两种不同的、具有不同纹理的碎片,它们属于同一类。
因为这个类是一个子类,所以我必须在super.init中将纹理设置为默认纹理。我确实更改了纹理,但在程序运行时只显示默认纹理。
我试着打印纹理,但它显示纹理已更改。怎么一回事?
注意:我使用跳棋棋子作为棋子的替身。红色的跳棋棋子是一个看台(红色团队的棋子)。图像应显示一个黑色的棋盘格
以下是问题所在:
这是打印出来的。
下面是派生和步枪手类的代码:
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")
}
}
}
https://stackoverflow.com/questions/41276503
复制相似问题