Jump to content

Container transformations don't apply when rendering on texure?


NessEngine
 Share

Recommended Posts

I try to render a container over a renderable texture, but the container transformations simply do not apply on the sprites inside. You can see it happens by taking the following code:

var renderer = PIXI.autoDetectRenderer(800, 600,{backgroundColor : 0x1099bb});
document.body.appendChild(renderer.view);

// create the root of the scene graph
var stage = new PIXI.Container();

// create a new Sprite using the texture
var texture = PIXI.Texture.fromImage('_assets/basics/bunny.png');
var bunny = new PIXI.Sprite(texture);

// move the sprite to the center of the screen
bunny.position.x = 200;
bunny.position.y = 150;

// create render texture and sprite
var render_texture = new PIXI.RenderTexture(renderer, 800, 800);
var render_texture_sprite = new PIXI.Sprite(render_texture);
stage.addChild (render_texture_sprite);

// create a container and add sprite to it
var container = new PIXI.Container();
container.addChild(bunny);

// these transformations will NOT apply, for some reason..
container.scale.x = 100;
container.position.y = 100;
// ????

// start animating
animate();
function animate() {
    requestAnimationFrame(animate);

  	render_texture.render(container);
    renderer.render(stage);
}

And paste it here http://pixijs.github.io/examples/

 

Is this a bug? or expected behavior?  How do I make the container apply its transformations on the sprite?

 

Thanks!

Link to comment
Share on other sites

answering self: looking at PIXI code I saw that when rendering on texture they have these lines:

// reset the matrix of the displatyObject..
displayObject.worldTransform.identity();

displayObject.currentBounds = null;

that reset the container transformations, but I don't see them updating transform after that. however, later they do:

 

for (i = 0, j = children.length; i < j; ++i)
{
     children[i].updateTransform();
}

So what I ended up trying (and it worked): I pushed my container into another empty container, and I rendered the parent container on the texture. This way all transformations apply. 

 

This still looks like a bug though. what do you think?

Link to comment
Share on other sites

That's correct solution, though I dont know if its a bug or feature. It depends on how do you understand local coordinates. If we consider that GLOBAL = worldTransform * LOCAL, then getLocalBounds(), renderTexture and cacheAsBitmap work as intended, because worldTransform does not affect local coords.

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