strouthas Posted May 20, 2018 Share Posted May 20, 2018 (edited) 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 May 20, 2018 by strouthas Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted May 20, 2018 Share Posted May 20, 2018 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. Quote Link to comment Share on other sites More sharing options...
strouthas Posted May 21, 2018 Author Share Posted May 21, 2018 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); Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted May 22, 2018 Share Posted May 22, 2018 Make a fiddle. Quote Link to comment Share on other sites More sharing options...
strouthas Posted May 22, 2018 Author Share Posted May 22, 2018 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. Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted May 23, 2018 Share Posted May 23, 2018 Somehow, this one works: https://jsfiddle.net/3xj6oxew/44/ Quote Link to comment Share on other sites More sharing options...
strouthas Posted May 23, 2018 Author Share Posted May 23, 2018 I know this works, but why my version with a second renderer doesn't? Is there something wrong in the code? It's not possible to use two renderers at the same time? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.