82 lines
2.6 KiB
JavaScript
82 lines
2.6 KiB
JavaScript
// Learn cc.Class:
|
|
// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html
|
|
// - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html
|
|
// Learn Attribute:
|
|
// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
|
|
// - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html
|
|
// Learn life-cycle callbacks:
|
|
// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
|
|
// - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html
|
|
|
|
cc.Class({
|
|
extends: cc.Component,
|
|
|
|
properties: {
|
|
// bar: {
|
|
// get () {
|
|
// return this._bar;
|
|
// },
|
|
// set (value) {
|
|
// this._bar = value;
|
|
// }
|
|
// },
|
|
},
|
|
|
|
// LIFE-CYCLE CALLBACKS:
|
|
|
|
// onLoad () {},
|
|
|
|
start () {
|
|
|
|
},
|
|
setdata(url,cbb){
|
|
this.sprite = this.node.getComponent(cc.Sprite)
|
|
this.time = 0
|
|
this.picidx = 0
|
|
this.changetime = 0.05
|
|
this.canup = false
|
|
var self = this
|
|
cc.loader.load(url +'?aaa=aa.jpg', function (err, texture) {
|
|
if (!err&&self.isValid) {
|
|
|
|
var res = new cc.SpriteFrame(texture);
|
|
if(self.sprite){
|
|
self.sprite.spriteFrame = res;
|
|
if(texture.height == 450 && texture.width == 450){
|
|
var tex = res.getTexture()
|
|
self.spsizew = tex.width/3
|
|
self.spsizeh = tex.height/3
|
|
tex.setFilters(cc.Texture2D.Filter.NEAREST, cc.Texture2D.Filter.NEAREST);
|
|
self.updatepic()
|
|
self.canup = true
|
|
}
|
|
|
|
}
|
|
}
|
|
if(cbb){
|
|
cbb();
|
|
}
|
|
});
|
|
},
|
|
updatepic(){
|
|
var dx = Math.floor(this.picidx%3)
|
|
var dy = Math.floor(this.picidx/3)
|
|
this.sprite.spriteFrame._rect.width = this.spsizew
|
|
this.sprite.spriteFrame._rect.height = this.spsizeh
|
|
this.sprite.spriteFrame._rect.x = dx*this.spsizew
|
|
this.sprite.spriteFrame._rect.y = dy*this.spsizeh
|
|
this.sprite.spriteFrame._calculateUV();
|
|
this.picidx++
|
|
this.picidx%=9
|
|
},
|
|
update (dt) {
|
|
if(this.canup){
|
|
this.time+=dt
|
|
if(this.time>this.changetime){
|
|
this.time = 0
|
|
this.updatepic()
|
|
}
|
|
}
|
|
},
|
|
});
|