Jump to content

DisplayObject.toGlobal not correct?


xingshang
 Share

Recommended Posts

  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?

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...