// 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

import { GameLogic } from "./update/GameLogic";


const {ccclass, property, executeInEditMode, playOnFocus} = cc._decorator;

@ccclass
@executeInEditMode
@playOnFocus
export default class flyImg extends  GameLogic {

    pos:cc.Vec2 = cc.v2(0,0);
    uvSpeed: number = 0;
    mat: cc.MaterialVariant = null;
    private _speed: number = 100;
    @property({type: cc.Integer})
    public get speed(): number {
        return this._speed;
    }
    public set speed(value: number) {
        this._speed = value;
        this.uvSpeed = value / this.node.height
    }

    onLoad () {
        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);
    }

    gameUpdate(dt: number): void {
        let uvSpeed = this.uvSpeed * dt;
        this.pos.y -= uvSpeed;
        this.mat.setProperty('center', this.pos);
    }
}
