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

148
Vistas
PixiJS: Draw line with mousemove

Pixijs I'm trying to draw a single line using OnMouseMove(), my problem is that everytime I move the mouse It leaves a trail

my progress codepen

var sprite = new PIXI.Graphics();
let initPointer = null;

const onMouseMove = (e) => {
  if (initPointer == null) return;
  sprite.lineStyle(2, 0xff0000, 1);
  sprite.moveTo(initPointer.x, initPointer.y);

  const mousePosRef = getMousePos(e);
  sprite.lineTo(mousePosRef.x, mousePosRef.y);
  console.log(sprite);

  annoRef.addChild(sprite);
  sprite = new PIXI.Graphics();
};
const onMouseDown = (e) => {
  const mousePosRef = getMousePos(e);
  initPointer = mousePosRef;
  // sprite.moveTo(initPointer.x, initPointer.y);
};

enter image description here

what I need, any help

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Changed your code a little bit: https://codepen.io/domis86/pen/LYOYrVx

main points:

  • see isMouseButtonDown variable usage
  • sprite.clear(); executed in onMouseMove - so on each move the Graphics object properties are resetted and one line is drawn. Previously on each move new line was "added" to Graphics object using sprite.moveTo and sprite.lineTo.
  • sprite = new PIXI.Graphics(); is executed in onMouseDown instead of onMouseUp. This way we create new Graphics object (a "line") when mouse is clicked - is more natural behaviour IMO.
  • Please rename your variable sprite because it suggests this is a Sprite ( https://pixijs.download/dev/docs/PIXI.Sprite.html ) but in reality it Graphics :) So line or graphics would be more suitable names IMHO ;)
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