Jump to content

Can you crop a renderTexture? OR copy only part of a displayObject?


WhiteRabbit
 Share

Recommended Posts

Hi there,

I have a collection of sprite animations happening inside of a PIXI Container.

I need to take a rectangle section of this animation and display it inside of a Spine animation using a Mesh. (this seems to be working all fine)

However, I am able to do get the full contents of the container and place it into my Spine animation no problem using renderTexture, but I only need a small section of its contents.

I thought I would be able to do something like this....

var party = PIXI.Container(); // Sprites of people in a party inside of here
var texture = PIXI.RenderTexture.create(party.width, party.height);
texture.frame = new PIXI.Rectangle(100, 0, 100, party.height); // also tried texture.trim
texture._updateUvs();

// on rAF update the mesh texture and apply to the mesh
renderer(party,texture);
slot.attachment.region.texture = texture;
slot.attachment.updateUVs();

Here it looks like it should only use a section from 100 pixels in from the left and only take a 100 pixel wide slice, but it doesn't.

 

I also thought I would create the renderTexture at the size of the slice I need....

var texture = PIXI.RenderTexture.create(100, party.height);
texture.frame = new PIXI.Rectangle(100, 0, 100, party.height); // also tried texture.trim

But this just takes a 100 pixel  section at the left most of my container.

Maybe I could apply a mask to the section I need and create a texture from that or something?

 

Edited by WhiteRabbit
Link to comment
Share on other sites

You don't need to set "frame" of renderTexture, its not that frame that is rendered by renderer, its frame that is shown in sprite later.

use

var myMatrix = new PIXI.Matrix();
myMatrix.tx = -100;
renderer.renderer(party, texture, undefined, myMatrix)

 

Also:

slot.attachment.region.texture = texture;
slot.attachment.updateUVs();

There's no guarantee that pixi-spine can change texture that way , there's special "hackTextureBySlot" or something like that.

Edited by ivan.popelyshev
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...