/*
文件名:SpriteClass.nut
路径:BaseClass/SpriteObject/SpriteClass.nut
创建日期:2024-05-05	09:35
文件用途:精灵类
*/
class CL_SpriteObject extends CL_BaseObject {

    SpriteFrame = null;

    constructor(...) {
        local C_Object;
        //创建空精灵
        if (vargv.len() == 0) {
            C_Object = Sprite_Create();
            base.constructor(C_Object);
        }
        //通过精灵指针创建
        else if (vargv.len() == 1) {
            C_Object = vargv[0];
            base.constructor(C_Object, true);
        }
        //通过路径创建
        else if (vargv.len() == 2) {
            C_Object = Sprite_Create();
            base.constructor(C_Object);
            local Path = vargv[0];
            local Idx = vargv[1];
            local Sf = CL_SpriteFrameObject(Path, Idx);
            SetFrame(Sf);
        }
    }

    //设置精灵帧
    function SetFrame(SpriteFrame) {
        this.SpriteFrame = SpriteFrame;
        Sprite_SetFrame(this.C_Object, SpriteFrame.C_Object);
    }

    //设置混合模式
    function SetMode(Mode) {
        Sprite_SetMode(this.C_Object, Mode);
    }

    //设置裁切
    function SetCropRect(Parameter1, Parameter2, ...) {
        if (vargv.len() == 0) {
            local Point1 = Parameter1;
            local Point2 = Parameter2;
            Sprite_SetCropRect(this.C_Object, Point1, Point2);
        } else if (vargv.len() == 2) {
            local X1 = Parameter1;
            local Y1 = Parameter2;
            local X2 = vargv[0];
            local Y2 = vargv[1];
            Sprite_SetCropRect(this.C_Object, X1, Y1, X2, Y2);
        }
    }
}