我有一个Swift4.2 SpriteKit场景,并在代码中找到了Sprite的SKNode 我想改变的质地。因为.childNode(withName :)返回一个SKNode 然后如何访问SKNode中包含的SKSpriteNode来更改纹理?
@IBOutlet weak var spritekitsceneFG: WKInterfaceSKScene!
var SpriteTick1 = SKNode()
SpriteTick1 = (spritekitsceneFG.scene?.childNode(withName: "SKSpriteTick1"))!
Want to change texture here!
print(SpriteTick1)
打印出SKNode会给出以下输出:
名称:'SKSpriteTick1'纹理:['tick'(64 x 64)]位置:{-48.000137,-56.000198}比例:{1.00,1.00}尺寸:{48,48}锚点:{0.5,0.5}旋转:0.00
如您所见,我希望能够以编程方式更改此处称为“ tick”的纹理
答案 0 :(得分:0)
好吧,我找到了一种这样做的方法。任何更好的想法都会受到欢迎。
var SpriteTick1 = SKSpriteNode()
SpriteTick1 = (spritekitsceneFG.scene?.childNode(withName: "SKSpriteTick1"))! as! SKSpriteNode
let textureCross = SKTexture(imageNamed: "cross")
SpriteTick1.texture = textureTick