Jump to content

mrmoor
 Share

Recommended Posts

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 ;)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 1 year later...

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;
	};

 

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