|
@@ -0,0 +1,43 @@
|
|
|
|
+// Learn TypeScript:
|
|
|
|
+// - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
|
|
|
|
+// Learn Attribute:
|
|
|
|
+// - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
|
|
|
|
+// Learn life-cycle callbacks:
|
|
|
|
+// - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
|
|
|
|
+
|
|
|
|
+const {ccclass, property, executeInEditMode, playOnFocus} = cc._decorator;
|
|
|
|
+
|
|
|
|
+@ccclass
|
|
|
|
+@executeInEditMode
|
|
|
|
+@playOnFocus
|
|
|
|
+export default class flyImg extends cc.Component {
|
|
|
|
+
|
|
|
|
+ pos:cc.Vec2 = cc.v2(0,0);
|
|
|
|
+ uvSpeed: number = 0;
|
|
|
|
+ mat: cc.MaterialVariant = null;
|
|
|
|
+ private _speed: number = 100;
|
|
|
|
+ @property({type: Number})
|
|
|
|
+ public get speed(): number {
|
|
|
|
+ return this._speed;
|
|
|
|
+ }
|
|
|
|
+ public set speed(value: number) {
|
|
|
|
+ this._speed = value;
|
|
|
|
+ this.uvSpeed = value / this.node.height
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ start () {
|
|
|
|
+ let spr = this.getComponent(cc.Sprite);
|
|
|
|
+ let mat = spr.getMaterial(0);
|
|
|
|
+ mat.setProperty('center', this.pos);
|
|
|
|
+ this.speed = 100;
|
|
|
|
+ this.mat = this.node.getComponent(cc.Sprite).getMaterial(0);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ protected update(dt: number): void {
|
|
|
|
+ let uvSpeed = this.uvSpeed * dt;
|
|
|
|
+ this.pos.y -= uvSpeed;
|
|
|
|
+ this.mat.setProperty('center', this.pos);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // update (dt) {}
|
|
|
|
+}
|