Jump to content

generateTexture with region doesn't work?


strouthas
 Share

Recommended Posts

Hello,

I am trying to take a screenshot of a specific part of my stage by using this simple code:

var ht = app.renderer.generateTexture(app.stage, 1, 1, new PIXI.Rectangle(1200, 400, 370, 310));               // the stage dimensions are 1600x900
var hp = new PIXI.Sprite(ht);
app.stage.addChild(hp);
 

whatever the rectangle x/y values, the texture is always grabbed from 0/0

second 'problem' is that I have to use canvas renderer to make this work or I get a blank texture which is pretty weird because with other display objects (even objects already added to the stage) the texture is there!

The renderer issue is not a big deal, I can use a custom renderer, the problem is that I can't crop a portion of my stage.

Am I missing something? Or maybe there is another way to achieve what I need?

Thanks!

[Edit] I can do it by generating a full screen stage and then create a new Texture with the frame I want, but the question is still valid; I found a bug or I did it wrong? And what about the webgl renderer blank grab?

 

 

Edited by strouthas
Link to comment
Share on other sites

generateTexture has its quirks, there are no guarantees that it'll work with both CanvasRenderer and region.

There was a PR to fix that, but it was too massive, we will fix it in v5 later: https://github.com/pixijs/pixi.js/pull/4632

I guess for now  you have to move stage position to get correct coords there.

Link to comment
Share on other sites

How can I use a second canvas renderer to generate the texture?

I don't want to forceCanvas in app params.

I tried the following but still get a blank screen.

var rnd = new PIXI.CanvasRenderer(1600, 900);
rnd.render(app.stage);
var ht = rnd.generateTexture(app.stage);
 

 

Link to comment
Share on other sites

https://jsfiddle.net/3xj6oxew/43/

 

var app = new PIXI.Application({ backgroundColor: 0xffffff, width: 1600, height: 900 });

document.body.append(app.view);

var txt = new PIXI.Text('This is a test');

app.stage.addChild(txt);

var rnd = new PIXI.CanvasRenderer(1600,900);

rnd.render(app.stage);

var texture = rnd.generateTexture(app.stage);

var sprite = new PIXI.Sprite(texture);

sprite.position.set(100, 100);

app.stage.addChild(sprite);
 

I am not sure if render(app.stage) is enough though.

Also, what is the difference between renderer.generateTexture() and RenderTexture? Both return a texture so it's a bit confusing.

 

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