Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

233
Views
PIXI JS - I want to change Width/height and Position of Rectangle with Mouse
var rectangle = new Graphics();
        rectangle.beginFill(0, 0.001);
        rectangle.lineStyle(1, 0xFF0000);
        rectangle.drawRect(5, 5, 200, 100);

        rectangle.interactive = true;
        rectangle.buttonMode = true;
        rectangle.on('pointerdown', onDragStart)
            .on('pointerup', onDragEnd)
            .on('pointerupoutside', onDragEnd)
            .on('pointermove', onDragMove);
        app.viewport.addChild(rectangle);

I'm using this code to create a rectangle and adding it to rectangle. This is the onDragMove Function

    function onDragMove() {
        if (this.dragging) {
            const newPosition = this.data.getLocalPosition(this.parent);
            this.width = newPosition.x;
            this.height = newPosition.y;
        
        }
    }

This is basically changing its width and height, but I also want to Drag the Rectangle when clicked inside the rectangle and dragged on the screen. Any suggestions how can I achieve this?

  • Borders to change width/height
  • clicking inside rectangle to drag on the screen.
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I created working example of dragging and resizing: https://www.pixiplayground.com/#/edit/SbpTjm7WKXbL51kmiG89W - please check.

  • when you click near bottom border of rectangle (+/- 20 px) then you will start resizing it.
  • when you click in any other place inside rectangle then you will drag it

Basing on this example i think you can implement resizing of other borders of rectangle etc :)

One note: please look at function drawRectangle :

function drawRectangle(rectangle)
{
    rectangle.clear();
    rectangle.beginFill(0, 0.001);
    rectangle.lineStyle(1, 0xFF0000);
    rectangle.drawRect(rectangle.myRectanglePosition[0], rectangle.myRectanglePosition[1], rectangle.myRectanglePosition[2], rectangle.myRectanglePosition[3]);
}

^ the rectangle.clear(); is called to redraw the PIXI.Graphics object. So on each frame we clear and draw it again on specific position with specific width & height.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!