Creator 版本号:1.5.0 beta3
运行时目标平台:Web
我有如下定义
// 测试精灵
testSprite1: cc.Sprite,
testSprite2: cc.Sprite,
testSprite3: cc.Sprite,
// 资源图
cardImg: cc.SpriteFrame,
所有的精灵和资源图都已经在编辑器中进行了绑定
在onLoad中实现如下代码
onLoad: function () {
this.testSprite1.spriteFrame = this.cardImg;
this.testSprite2.spriteFrame = this.cardImg;
this.testSprite1.spriteFrame.setRect(cc.rect(0,0,90,120));
this.testSprite2.spriteFrame.setRect(cc.rect(0,240,90,120));
},
此时会发现,testSprite1和testSprite2显示的图片区域是一样的
也就是只会显示cardImg上这个区域的(0,240,90,120),不会显示(0,0,90,120)这个区域的
通过webstorm调试发现,testSprite1和testSprite2中的spriteFrame的_rect区域都是一样的,都是(0,240,90,120)
所以显示的区域是一样的
这里我还可以理解成他们引用了同一个内存地址,所以修改其中一个的显示区域,另外的显示也会发生变化
但是如果我在在一个按钮的点击回调中,给第三个精灵(testSprite3)进行同样的操作,
//
onClickSomeButton: function () {
this.testSprite3.spriteFrame = this.cardImg;
this.testSprite3.spriteFrame.setRect(cc.rect(0,360,90,120));
},
按照刚才的特性,应该三个精灵显示的内容还是一样,并且都会显示cardImage中(0,360,90,120)这个区域的内容
但是实际上只有testSprite3显示了这个区域的内容,
testSprite1,testSprite2还是维持了之前的显示区域,
通过webstorm调试发现,其实这三个sprite的spriteFrame的_rect区域都已经一样,都已经是(0,360,90,120)
那为何此时testSprite1,testSprite2的显示没有同步呢?
期待开发组的解答