Link

首页

Tweet

书单

about me

Command

友情链接

Category

Egret Sprite TouchEvent Code


class Main extends egret.DisplayObjectContainer{

    public constructor() {
        super();
        this.addEventListener(egret.Event.ADDED_TO_STAGE,this.onAddToStage,this);
    }

    private onAddToStage(event:egret.Event){
        var spr:egret.Sprite = new egret.Sprite();

        var a:egret.Shape = new egret.Shape();
        a.graphics.beginFill(0xff0000);
        a.graphics.drawCircle(0,0,50);
        a.graphics.endFill();

        var b:egret.Shape = new egret.Shape();
        b.graphics.beginFill(0x00ff00);
        b.graphics.drawCircle(0,0,50);
        b.graphics.endFill();
        b.x = 100;
        spr.addChild(a);
        spr.addChild(b);

        spr.x = 100;
        spr.y = 100;
        spr.width = 200;
        spr.height = 200;

        spr.touchEnabled = true;
        spr.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.click,this);
        this.addChild(spr);
    }

    private click(evt:egret.TouchEvent):void
    {
        evt.currentTarget.x += 10;
    }

}