Jump to content

PIXI Graphics issue


Henri Kiiski
 Share

Recommended Posts

Hi all,
I'm trying to create a grid of white 20pixel squares right next to each other but it's not working out as expected.

app.stage.removeChildren();
cells = [];
for (let y = 0; y < app.view.height; y += cellWidth) {
  let arr = [];
  for (let x = 0; x < app.view.width; x += cellWidth){
    let square = new PIXI.Graphics();
    square.beginFill(dead);
    square.drawRect(x, y, cellWidth, cellWidth).endFill();
    square.position.set(x, y);
    square.interactive = true;
    app.stage.addChild(square);
    arr.push(dead);
  }
  cells.push(arr);
}

This is what I got:

image.png.e97b9f22dedd86b0cb55e4e1de9b71e6.png

In the above picture you shouldn't be able to see any green but for some reason the white cells do not get placed next to each other. However looking at graphics.geometry.points the cells have correct points. I.e. a cell is touching it's neighbours.

Any help/ideas would be appreciated.

Link to comment
Share on other sites

Hello and Welcome to the forums!

    square.drawRect(x, y, cellWidth, cellWidth).endFill();
    square.position.set(x, y);

So , your shape has local coords (x,y). And whole graphics is also transformed to position (x,y). That's (2*x, 2*y) for shape.

"position" does not set position of a shape inside graphics. Its setting position of whole graphics. Please look up what "Transform" is. Cant give you articles, there should be plenty not related to pixi, its the same in all 2d flash-like renderers. Position+scale+rotation+pivot(in pixi). Applied to everything that is inside, not just "searching for element inside and changing its position"

Edited by ivan.popelyshev
Link to comment
Share on other sites

45 minutes ago, ivan.popelyshev said:

Hello and Welcome to the forums!

    square.drawRect(x, y, cellWidth, cellWidth).endFill();
    square.position.set(x, y);

So , your shape has local coords (x,y). And whole graphics is also transformed to position (x,y). That's (2*x, 2*y) for shape.

"position" does not set position of a shape inside graphics. Its setting position of whole graphics. Please look up what "Transform" is. Cant give you articles, there should be plenty not related to pixi, its the same in all 2d flash-like renderers. Position+scale+rotation+pivot(in pixi). Applied to everything that is inside, not just "searching for element inside and changing its position"

Thanks a lot for the help Ivan! I was able to get it working now.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...