Jump to content

position (x, y) does not work


zacuve
 Share

Recommended Posts

position (x, y) does not work

capture http://prntscr.com/msqhg3

 var my_photo = new PIXI.Sprite(resources.my_photo.texture);

my_photo.width = 200;
my_photo.height = 200;

my_photo.position.x = 200;
my_photo.position.y = 150;

container.addChild(my_photo);


var tex = this.app.renderer.generateTexture(container);
var combinedSprite = new PIXI.Sprite(tex);

//PIXI.loader.reset();
this.app.stage.addChild(combinedSprite);

Screenshot_6.png

Link to comment
Share on other sites

      I think the problem is here

   var tex = this.app.renderer.generateTexture(container);
      var combinedSprite = new PIXI.Sprite(tex);
      //PIXI.loader.reset();
      this.app.stage.addChild(combinedSprite);

Link to comment
Share on other sites

generateTexture() doesnt remember position of element, it takes its bounds and renders everything inside to a texture (0,0)-(w,h).

Usually, when i use it, i remember (x,y) of bounds to DEFAULT ANCHOR inside that texture

somehint like 

var bounds = container.getBounds();
var texture = renderer.generateTexture(container, undefined, undefined, bounds);
texture.defaultAnchor.set(-bounds.x / bounds.width, -bounds.y / bounds.height);

then when you create the sprite , anchor will be automatically set. Do remember that sprite.position will still be 0, my method affects only anchor.

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