首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >类纹理会更改,但不会显示

类纹理会更改,但不会显示
EN

Stack Overflow用户
提问于 2016-12-22 13:45:24
回答 0查看 14关注 0票数 0

在我正在制作的程序中,我试图有两种不同的、具有不同纹理的碎片,它们属于同一类。

因为这个类是一个子类,所以我必须在super.init中将纹理设置为默认纹理。我确实更改了纹理,但在程序运行时只显示默认纹理。

我试着打印纹理,但它显示纹理已更改。怎么一回事?

注意:我使用跳棋棋子作为棋子的替身。红色的跳棋棋子是一个看台(红色团队的棋子)。图像应显示一个黑色的棋盘格

以下是问题所在:

这是打印出来的。

下面是派生和步枪手类的代码:

代码语言:javascript
代码运行次数:0
运行
复制
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")
        }
    }

}
EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41276503

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档