-
Creator 版本:2.1.2
-
目标平台: Web
我的代码大概如下,编辑器拖了两个png到textureA和textureB,然后点击按钮调用changeTexture
但是显示有点奇怪
是什么原因呢?
@property({ type: cc.Texture2D })
textureA: cc.Texture2D = null
@property({ type: cc.Texture2D })
textureB: cc.Texture2D = null
changeTexture() {
let sp = cc.find(“Canvas/cocos”).getComponent(cc.Sprite)
if (this.textureA === sp.spriteFrame.getTexture()) {
sp.spriteFrame.setTexture(this.textureB)
cc.log(“TexB”)
} else {
sp.spriteFrame.setTexture(this.textureA)
cc.log(“TexA”)
}
}
@property({ type: cc.Texture2D })
textureA: cc.Texture2D = null
@property({ type: cc.Texture2D })
textureB: cc.Texture2D = null
changeTexture() {
let sp = cc.find(“Canvas/cocos”).getComponent(cc.Sprite)
if (this.textureA === sp.spriteFrame.getTexture()) {
sp.spriteFrame.setTexture(this.textureB)
cc.log(“TexB”)
} else {
sp.spriteFrame.setTexture(this.textureA)
cc.log(“TexA”)
}
}
图片是

