mrmoor Posted August 20, 2015 Share Posted August 20, 2015 Hi Pixi Gurus , I have played a bit with Pixi and now I'm doing some productive stuff with it, but I stuck with resizing.Currently I'm loading and cuting out a part of my Image, but how can I resize this part as (Base)Texture to ex. 64x64?var baseTexture = new PIXI.BaseTexture.fromImage("assets/demo.png", false, PIXI.SCALE_MODES.NEAREST);var size = new PIXI.Rectangle(16, 32, 16, 16);var texture = new PIXI.Texture(baseTexture,size);Thank you in advance Quote Link to comment Share on other sites More sharing options...
xerver Posted August 20, 2015 Share Posted August 20, 2015 Put it in a sprite and scale the sprite. Quote Link to comment Share on other sites More sharing options...
mrmoor Posted August 20, 2015 Author Share Posted August 20, 2015 ok thank you, there is no way to resize the (Base)Texture so I can use it in multiple Textures? Quote Link to comment Share on other sites More sharing options...
xerver Posted August 20, 2015 Share Posted August 20, 2015 ok thank you, there is no way to resize the (Base)Texture so I can use it in multiple Textures? A texture is just a description of what rectangle of a base texture to use, a base texture is just a description of what image to use. A sprite describes where and how to draw a texture in the world. This includes scaling and other things. Quote Link to comment Share on other sites More sharing options...
ben0bi Posted October 8, 2016 Share Posted October 8, 2016 I effectively need a way to get the texture scaled on pixel basis, to output the created texture as array to a selfmade LED screen. I use a RenderTexture which renders the whole screen, and want to rescale the texture (on pixel data basis, as said before). I cannot get it to work: tex = new RenderTexture(renderer, mywidth, myheight, PIXI.SCALE_MODE_NEAREST, scale) => I scaled it down to myWidth, myHeight but it only takes the myWidth, myHeight part on the screen itself and scales that one down, much blank space left. tex = new RenderTexture(renderer, renderer.width, renderer.height, PIXI_SCALE_MODE_NEAREST, scale) => scaling works and it takes the whole image, but the output texture is as big as the screen itself, also with much blank space. I can not find a way to get a 100x100 texture out of a 400x400 screen, scaled properly. Can anyone help here, please? And please, no sprites. I need the pixel data at the end (to remember, this is the third time. ) Thanks in advance for your answers. [EDIT] OK I got it, we need sprites. It works now. Here is my code for all who may need it. // get screen data. this.getScreenAsTexture = function(renderWidth, renderHeight) { // _PIXIRootStage is the container which has to be scaled and rendered to texture. // _PIXIRenderer is the renderer of this class. var renderer = _PIXIRenderer; // set render size if <= 0 if(renderWidth <= 0) renderWidth = renderer.width; if(renderHeight <= 0) renderHeight = renderer.height; // compute scaling factor. var scale = 1; var sc = renderWidth; var sc2 = renderer.width; if(renderHeight<renderWidth) //[edit] use smaller instead of bigger value. { sc = renderHeight; sc2 = renderer.height; } if(sc > 0 && sc2 > 0) scale = sc / sc2; // first, render the screen to a texture. var origTex = new PIXI.RenderTexture(renderer, renderer.width, renderer.height); origTex.render(_PIXIRootStage); // create sprite and container to resize the texture var stage = new PIXI.Container(); var sprite = new PIXI.Sprite(origTex); sprite.scale.x = scale; sprite.scale.y = scale; stage.addChild(sprite); // render the original again in scaled mode. var renderTex = new PIXI.RenderTexture(renderer, renderWidth, renderHeight); renderTex.render(stage); return renderTex; }; dmitrymatveev 1 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.