xingshang Posted August 5, 2020 Share Posted August 5, 2020 let g = new PIXI.Graphics() g.beginFill(0x553311) g.drawRect(0,0, 100, 100); g.endFill(); let sp1 = new Sprite(g.generateCanvasTexture()); sp1.width = 100; sp1.height = 100; g = new PIXI.Graphics() g.beginFill(0xff3311) g.drawRect(0,0, 50, 50); g.endFill(); let sp2 = new Sprite(g.generateCanvasTexture()); sp2.width = 50; sp2.height = 50; sp2.x = 20; sp2.y = 10; let container = new PIXI.Container(); container.addChild(sp1); container.addChild(sp2); container.x = 100; container.y = 100; app.stage.addChild(container); let pos = sp2.toGlobal(sp2.position); console.log(pos.x + ' ' + pos.y); Console show 140 120, i think it should be 120 110. container position is 100, 100, the small rectangle position in container is 20, 10, why it global position is 140, 120? Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted August 5, 2020 Share Posted August 5, 2020 (edited) because you have to use toGlobal(new PIXI.Point(0,0)) - point 0 om sp2 translates to "sp2.position" in container, and you want global value. Edited August 5, 2020 by ivan.popelyshev xingshang 1 Quote Link to comment Share on other sites More sharing options...
xingshang Posted August 5, 2020 Author Share Posted August 5, 2020 1 hour ago, ivan.popelyshev said: because you have to use toGlobal(new PIXI.Point(0,0)) - point 0 om sp2 translates to "sp2.position" in container, and you want global value. Thanks, worked! 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.