Jump to content

1x1 texture from drawRect


Dzugaru
 Share

Recommended Posts

I want to draw some lines and rects, usual strategy for doing this in other game engines is using a 1x1 texture in a scaled and tinted sprite, but in PixiJS I found a strange problem with this.

Texture from drawRect(0,0,1,1) doesn't work, while drawRect(0,0,2,2) (or 2x1, 1x2, or 2x2 with frame = new Rectangle(0,0,1,1)) works.

https://jsfiddle.net/Dzugaru/84otd4dn/

Link to comment
Share on other sites

You can make a 1x1 texture with generateCanvasTexture by changing your demo like this:

var renderer = PIXI.autoDetectRenderer(256, 256);
document.body.appendChild(renderer.view);
var stage = new PIXI.Container();

var rect = new PIXI.Graphics();
rect.beginFill(0xFFFFFF, 1);
rect.drawRect(0, 0, 1, 1);
rect.endFill();                

//////////////////////////////////////////////////////////////////////////////////////
var tex = rect.generateCanvasTexture(); //
//////////////////////////////////////////////////////////////////////////////////////

var s = new PIXI.Sprite(tex);
s.width = s.height = 32;
s.x = s.y = 128 - s.width / 2;
stage.addChild(s);

renderer.render(stage);

 

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