Branlin Posted July 28, 2017 Share Posted July 28, 2017 var app = new PIXI.Application(800, 600, {forceCanvas:true, backgroundColor : 0xffffff}); document.body.appendChild(app.view); var bunny = PIXI.Sprite.fromImage('bunny.png') var pixels = app.renderer.extract.pixels(bunny); console.log(pixels) in devtool console: Quote > Uint8ClampedArray(4) [0, 0, 0, 0] I need pixels, but I'm a strange result. Quote Link to comment Share on other sites More sharing options...
themoonrat Posted July 28, 2017 Share Posted July 28, 2017 the renderer hasn't actually rendered anything yet. Force the renderer to render what you've put on screen first via app.render(); Quote Link to comment Share on other sites More sharing options...
lloydevans Posted July 28, 2017 Share Posted July 28, 2017 Yes, and also make sure the texture is loaded. themoonrat 1 Quote Link to comment Share on other sites More sharing options...
Branlin Posted July 28, 2017 Author Share Posted July 28, 2017 Thank all! app.render() is no need It's work. const app, resources; app = new PIXI.Application(800, 600, {forceCanvas:true, backgroundColor : 0xffffff}); document.body.appendChild(app.view); loader = new PIXI.loaders.Loader(); loader.add('bunny', 'bunny.png') loader.onComplete.add((result) => { resources = result.resources; run(); }); loader.load(); // function run() { var bunny = new PIXI.Sprite(resources.bunny.texture) app.stage.addChild(bunny); var pixels = app.renderer.extract.pixels(bunny); console.log(pixels); } Quote Link to comment Share on other sites More sharing options...
lloydevans Posted July 28, 2017 Share Posted July 28, 2017 app.render would of been needed if you'd wanted to extract the pixels from the renderer, but you are extracting them from the texture itself The texture having been loaded is needed in both cases. ivan.popelyshev and Branlin 2 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.