https://linen.dev logo
Join Discord
Powered by
# openfl
  • t

    thousands-state-46635

    08/07/2022, 9:53 AM
    Copy code
    hx
    package;
    
    import openfl.display.Graphics;
    import openfl.geom.Point;
    import openfl.events.Event;
    import openfl.events.MouseEvent;
    import openfl.display.BitmapData;
    import openfl.display.Bitmap;
    import openfl.display.Sprite;
    
    class Main extends Sprite
    {
    
        var canvasWidth:Int = 400;
        var canvasHeight:Int = 400;
        var canvasColor:Int = 0xFFFFFFFF;
        var canvas:Bitmap;
        var brushColor:Int = 0xFF000000;
    
        var downMousePos:Point;
        var curMousePos:Point;
    
        public function new()
        {
            super();
            init();
            addEventListeners();
        }
        
        private function onUpdate(ev:Event) {
        }
    
        private function onMouseDown(ev:MouseEvent) {
            downMousePos = new Point(ev.localX, ev.localY);
            graphics.moveTo(downMousePos.x, downMousePos.y);
        }
    
        private function onMouseMove(ev:MouseEvent) {
            if (downMousePos == null) return;
            graphics.lineTo(ev.localX, ev.localY);
            downMousePos.setTo(ev.localX, ev.localY);
        }
    
        private function onMouseUp(ev:MouseEvent) {
            downMousePos = null;
        }
    
        private function init() {
            canvas = new Bitmap(new BitmapData(canvasWidth, canvasHeight, false, canvasColor));
            addChild(canvas);
            graphics.lineStyle(3, brushColor, 1, false, NORMAL, null, null, 3);
        }
    
        private function addEventListeners() {
            addEventListener(Event.ENTER_FRAME, onUpdate);
            addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
            addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
            addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
        }
    }
  • t

    thousands-state-46635

    08/07/2022, 9:58 AM
    dont know hwo tof ix this
  • b

    best-agent-85158

    08/07/2022, 11:41 AM
    i have a drawcanvas class that works really great for my app. planning to opensource that part of my app, ill send it here until then:
  • b

    best-agent-85158

    08/07/2022, 11:41 AM
    EventDispatcher is just my way of implementing drawing history. you can ignore that part
  • b

    bulky-exabyte-6537

    08/07/2022, 1:00 PM
    ur drawing into the wrong graphics
  • b

    bulky-exabyte-6537

    08/07/2022, 1:00 PM
    use
    canvas.graphics
    instead of
    graphics
  • b

    bulky-exabyte-6537

    08/07/2022, 1:00 PM
    @thousands-state-46635
  • t

    thousands-state-46635

    08/07/2022, 1:35 PM
    oh ok
  • t

    thousands-state-46635

    08/07/2022, 1:36 PM
    ho shit tysm!
  • t

    thousands-state-46635

    08/07/2022, 1:37 PM
    canvas doesnt have a graphics property
  • t

    thousands-state-46635

    08/07/2022, 1:37 PM
    canvas is a variable made by me
  • t

    thousands-state-46635

    08/07/2022, 1:40 PM
    oh i getwhat you mean
  • t

    thousands-state-46635

    08/07/2022, 1:41 PM
    but now it doesnt render anything
  • t

    thousands-state-46635

    08/07/2022, 1:41 PM
    i mean other than the shaep, but i cant draw..
  • t

    thousands-state-46635

    08/07/2022, 1:42 PM
    Copy code
    hx
    package;
    
    import openfl.display.Shape;
    import openfl.display.Graphics;
    import openfl.geom.Point;
    import openfl.events.Event;
    import openfl.events.MouseEvent;
    import openfl.display.BitmapData;
    import openfl.display.Bitmap;
    import openfl.display.Sprite;
    
    class Main extends Sprite
    {
    
        var canvasWidth:Int = 400;
        var canvasHeight:Int = 400;
        var canvasColor:Int = 0xFFFFFFFF;
        var canvas:Shape;
        var brushColor:Int = 0xFF000000;
    
        var downMousePos:Point;
        var curMousePos:Point;
    
        public function new()
        {
            super();
            init();
            addEventListeners();
        }
        
        private function onUpdate(ev:Event) {
        }
    
        private function onMouseDown(ev:MouseEvent) {
            downMousePos = new Point(ev.localX, ev.localY);
            canvas.graphics.moveTo(downMousePos.x, downMousePos.y);
        }
    
        private function onMouseMove(ev:MouseEvent) {
            if (downMousePos == null) return;
            canvas.graphics.lineTo(ev.localX, ev.localY);
            downMousePos.setTo(ev.localX, ev.localY);
        }
    
        private function onMouseUp(ev:MouseEvent) {
            downMousePos = null;
        }
    
        private function init() {
            canvas = new Shape();
            canvas.graphics.drawRect(0, 0, canvasWidth, canvasHeight);
            canvas.graphics.lineStyle(3, brushColor, 1, false, NORMAL, null, null, 3);
            addChild(canvas);
        }
    
        private function addEventListeners() {
            addEventListener(Event.ENTER_FRAME, onUpdate);
            addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
            addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
            addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
        }
    }
  • b

    bulky-exabyte-6537

    08/07/2022, 1:51 PM
    hm not sure
  • t

    thousands-state-46635

    08/07/2022, 1:57 PM
    yeah
  • t

    thousands-state-46635

    08/07/2022, 1:57 PM
    tried shahar's stuff to but it seems it wont work on m end
    Copy code
    hx
    package;
    
    import openfl.display.Shape;
    import openfl.display.Graphics;
    import openfl.geom.Point;
    import openfl.events.Event;
    import openfl.events.MouseEvent;
    import openfl.display.BitmapData;
    import openfl.display.Bitmap;
    import openfl.display.Sprite;
    
    class Main extends Sprite
    {
    
        var canvasWidth:Int = 400;
        var canvasHeight:Int = 400;
        var canvasColor:Int = 0xFFFFFFFF;
        var canvas:Shape;
        var brushColor:Int = 0xFF000000;
    
        var downMousePos:Point;
        var curMousePos:Point;
    
        var brushLayer:Shape;
    
        public function new()
        {
            super();
            init();
            addEventListeners();
        }
        
        private function onUpdate(ev:Event) {
        }
    
        private function onMouseDown(ev:MouseEvent) {
            downMousePos = new Point(ev.localX, ev.localY);
            brushLayer.graphics.moveTo(downMousePos.x, downMousePos.y);
            brushLayer.graphics.lineStyle(3, 0xFF000000, 1, false, NORMAL, null, null, 3);
        }
    
        private function onMouseMove(ev:MouseEvent) {
            if (downMousePos == null) return;
            brushLayer.graphics.lineTo(ev.localX, ev.localY);
            downMousePos.setTo(ev.localX, ev.localY);
        }
    
        private function onMouseUp(ev:MouseEvent) {
            downMousePos = null;
        }
    
        private function init() {
            canvas = new Shape();
            addChild(canvas);
            canvas.graphics.drawRect(0, 0, width, height);
            brushLayer = new Shape();
            addChild(brushLayer);
        }
    
        private function addEventListeners() {
            addEventListener(Event.ENTER_FRAME, onUpdate);
            addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
            addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
            addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
        }
    }
  • b

    best-agent-85158

    08/07/2022, 2:19 PM
    weird... this is how it works for me:
  • t

    thousands-state-46635

    08/08/2022, 7:23 PM
    Hmm weird...ill figure it out later
  • t

    thousands-state-46635

    08/08/2022, 7:24 PM
    Also what are you using for UI? It looks amazing
  • b

    best-agent-85158

    08/08/2022, 7:24 PM
    thanks! im using HaxeUI - looks great and really nice to use 😄
  • t

    thousands-state-46635

    08/08/2022, 7:28 PM
    oo nice!
  • t

    thousands-state-46635

    08/08/2022, 7:28 PM
    Itscompatible with OpenFL?
  • e

    elegant-twilight-61392

    08/08/2022, 7:36 PM
    haxeui has openfl and flixel backends
  • t

    thousands-state-46635

    08/08/2022, 7:56 PM
    Oh nice
  • w

    witty-island-52596

    08/08/2022, 11:40 PM
    I seem to have an issue on hashlink where applying a filters to a sprite seems to effect various other sprites
  • w

    witty-island-52596

    08/08/2022, 11:41 PM
    windows builds work fine
  • w

    witty-island-52596

    08/08/2022, 11:41 PM
    I'm trying to build a small repro (the project is massive) but just wondering if this is a known issue
  • c

    curved-tiger-81069

    08/09/2022, 3:19 AM
    heya so, im trying to make animated sprites and it seems to work all fine on windows but on html5 it just doesnt show up, and the console doesnt tell me anything
12345...57Latest