96 lines
2.2 KiB
JavaScript
96 lines
2.2 KiB
JavaScript
"use strict";
|
|
cc._RF.push(module, 'b48a2ukFF1FlJGSkUcHUIET', 'CtrlFluxayTexture');
|
|
// Script/CtrlFluxayTexture.js
|
|
|
|
"use strict";
|
|
|
|
cc.Class({
|
|
"extends": cc.Component,
|
|
properties: {
|
|
m_delayTime: {
|
|
"default": 0
|
|
},
|
|
m_fluxayTime: {
|
|
"default": 1
|
|
},
|
|
m_intervalTime: {
|
|
"default": 1
|
|
},
|
|
m_scale: {
|
|
"default": 1
|
|
},
|
|
m_angle: {
|
|
"default": 0
|
|
},
|
|
m_reviseStartTime: {
|
|
"default": 0
|
|
},
|
|
m_reviseTimeScale: {
|
|
"default": 1
|
|
}
|
|
},
|
|
ctor: function ctor() {
|
|
this._time = 0;
|
|
},
|
|
onLoad: function onLoad() {
|
|
this._time -= this.m_delayTime;
|
|
var sprite = this.node.getComponent(cc.Sprite);
|
|
this._material = sprite.getMaterial(0);
|
|
|
|
this._material.setProperty("u_scale", this.m_scale);
|
|
|
|
this._material.setProperty("u_angle", this.m_angle);
|
|
|
|
this.refreshSpriteFrameData();
|
|
},
|
|
update: function update(dt) {
|
|
if (this._time > this.m_fluxayTime + this.m_intervalTime) {
|
|
this._time = 0;
|
|
}
|
|
|
|
var u_time = this._time / this.m_fluxayTime;
|
|
|
|
if (this._time > this.m_fluxayTime) {
|
|
u_time = 1 + (this._time - this.m_fluxayTime) / this.m_intervalTime;
|
|
}
|
|
|
|
if (this.m_reviseTimeScale != null && this.m_reviseStartTime != null) {
|
|
u_time = u_time / this.m_reviseTimeScale;
|
|
u_time -= this.m_reviseStartTime;
|
|
}
|
|
|
|
this._material.setProperty("u_time", u_time);
|
|
|
|
this._time += dt;
|
|
},
|
|
refreshSpriteFrameData: function refreshSpriteFrameData() {
|
|
var sprite = this.node.getComponent(cc.Sprite);
|
|
var material = sprite.getMaterial(0);
|
|
var frame = sprite.spriteFrame;
|
|
|
|
if (frame != null) {
|
|
// xMin
|
|
var l = frame.uv[0]; // xMax
|
|
|
|
var r = frame.uv[6]; // yMax
|
|
|
|
var b = frame.uv[3]; // yMin
|
|
|
|
var t = frame.uv[5]; // 纹理在合图中的四个边界 uv 坐标
|
|
|
|
var u_uvOffset = new cc.Vec4(l, t, r, b); // 纹理是否旋转
|
|
|
|
var u_uvRotated = frame.isRotated() ? 1.0 : 0.0; // 设置材质的属性
|
|
|
|
if (material.getProperty("u_uvOffset") !== undefined) {
|
|
material.setProperty("u_uvOffset", u_uvOffset);
|
|
}
|
|
|
|
if (material.getProperty("u_uvRotated") !== undefined) {
|
|
material.setProperty("u_uvRotated", u_uvRotated);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
cc._RF.pop(); |