Skip to content

Understanding the coordinate space for Lines vs Polygons #2729

Answered by eonarheim
davobutt asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @davobutt this is a great question!

Graphics do indeed live in their own local space and are completely separate from each other.

The actor graphics component centers by default around around the actor's position. The property that controls this is the ex.Actor.graphics.anchor which is set to (0.5, 0.5) by default. The tricky thing about layering graphics like ex.Line and ex.Polygon is it is currently done using their bounds.

If you align the graphics to the top left corner you can layer them (but requires some tweaks to the original math)

hexagon.graphics.anchor = ex.vec(0, 0);
hexagon.graphics.use(
  new ex.Polygon({
    points: [
      ex.vec(0, 50),
      ex.vec(-43, 25),
      ex.vec

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@davobutt
Comment options

Answer selected by davobutt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants