Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

247
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda