vendredi 16 septembre 2016

Drawing pictures on sprites

I am coding for drawing picture on sprites in different places. But I have received a response of simply drawing picture without drawing on sprites in different places.

Here is what I have tried so far:

package {

import flash.display.Graphics;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.geom.Point;

public class draw_lines_001 extends Sprite {

    private var clicked:Boolean=false;
    private var sprite:Sprite=new Sprite();
    private var g:Graphics=sprite.graphics;

    public function draw_lines_001():void {
        draw();
    }

    private function draw():void{           
        stage.addEventListener(MouseEvent.MOUSE_DOWN,mouse_down);
        stage.addEventListener(MouseEvent.MOUSE_MOVE,mouse_move);
        stage.addEventListener(MouseEvent.MOUSE_UP,mouse_up);

// addEventListener(Event.ENTER_FRAME,enter_frame); }

    private function mouse_down(e:MouseEvent):void{
        clicked=true;
        var point_global:Point=new Point(stage.mouseX,stage.mouseY);
        var point_local:Point=sprite.globalToLocal(point_global);
        g.moveTo(point_local.x,point_local.y);
    }

    private function mouse_move(e:MouseEvent):void{
        if(clicked){
        var point_global:Point=new Point(stage.mouseX,stage.mouseY);
        var point_local:Point=sprite.globalToLocal(point_global);
        g.lineStyle(5,0xffcccc,0.1);
        g.lineTo(point_local.x,point_local.y);
        stage.addChild(sprite);
        sprite.x=10;
        sprite.y=10;
        }
    }

    private function mouse_up(e:MouseEvent):void{
        clicked=false;
    }
}

}

Aucun commentaire:

Enregistrer un commentaire