ccRect.js
1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* 设置按钮状态
* 0 未聚焦
* 1 聚焦
* 2 未聚焦 + 附加(例如:已收藏)
* 3 聚焦 + 附加(例如:已收藏)
*/
cc.Class({
extends: cc.Component,
properties: {
renderTexture : {
default : null,
type : cc.Texture2D
},
renderRects : {
default : [],
type : [cc.Rect]
},
_iRenderRectIndex : 0,
},
onLoad:function() {
this.setRenderRect(0);//默认加载先取第一张
},
setRenderTexture : function (texture) {
this.renderTexture = texture;
},
setRenderRect : function (index) {
this._iRenderRectIndex = index;
let rectRender = this.renderRects[index];
if(this.node.getComponent(cc.Sprite)&&rectRender){
this.node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(this.renderTexture,rectRender.clone());//原先的写法,有点啰嗦
this.node.width = rectRender.width;
this.node.height = rectRender.height;
}
},
getRenderRectIndex : function () {
return this._iRenderRectIndex;
},
});