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

158
Views
How to use absolute coords in pixijs

My question is about moving lines and rects using absolute coords.

  1. I created line:
const line = new PIXI.Graphics();
line.lineStyle(2, 0xffffff);
line.moveTo(100, 200);
line.lineTo(300, 200);
app.stage.addChild(line);

But if I will try to set coords by changing x/y it will be relative to created pos:

line.x = 200; // real x will be 300
line.y = 200; // real y will be 400

How should I move this line if i need to set absolute coords on view? Should I always calc absolute coords using current?

  1. Same question about rect, I create it like this:
const blueBox = new PIXI.Graphics();
blueBox.beginFill(0x0000ff);
blueBox.drawRect(50, 50, 50, 50);
blueBox.endFill();
app.stage.addChild(blueBox);

If i will try to move it using x/y i will do same as line - x/y are relative, ok. I can always draw rects at 0/0 point and then move them, but is it correct desigin, is there other way?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

As a general rule you shouldn't trigger redraws on Graphics objects if they don't change visually. It's a computationally expensive operation, and merely repositioning the object doesn't justify calling it.

A better alternative is painting the line or rect using local coordinates and placing it at the target absolute position by setting the position property. I prefer to keep (0, 0) as the center of the shape, but choosing the top-left corner or any other point of reference is also valid. For a rectangle it would look like this:

const blueBox = new PIXI.Graphics();
blueBox.beginFill(0x0000ff);
blueBox.drawRect(-25, -25, 50, 50);
blueBox.endFill();
blueBox.position.set(25, 25);
app.stage.addChild(blueBox);

From this point, all changes to the absolute position of the rectangle should happen by changing the position property, not by redrawing the graphics with the new coordinates.

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!