Henri Kiiski Posted April 7, 2020 Share Posted April 7, 2020 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: 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. Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted April 7, 2020 Share Posted April 7, 2020 (edited) 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 April 7, 2020 by ivan.popelyshev Quote Link to comment Share on other sites More sharing options...
Henri Kiiski Posted April 7, 2020 Author Share Posted April 7, 2020 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. ivan.popelyshev 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.