Jump to content

Shapes rendered using PIXI.Graphics not rendering on WebGLRenderer but rendering fine on CanvasRenderer [solved]


xTiming
 Share

Recommended Posts

I recently upgraded to pixi v4.0.1 from pixi v3.x.x.  Since then some simple code that was just rendering a colored square has stopped working when using the WebGLRenderer.  Relevant code below:

var PlayerObject = function(uniqueId, world, x, y, velx, vely, clientPlayerObj) {
    // ...

    var color = Math.floor(Math.random() * 0xFFFFFF);
    this.renderObject = new PIXI.Graphics();
    this.renderObject.beginFill(color, 0xFF);
    this.renderObject.drawRect(x * 16, y * 16, 32, 32);

    // ...
};

World.prototype.addGameObject = function(gameObj) {
    // ...

    if (gameObj.renderObject != null) {
        this.renderRoot.addChild(gameObj.renderObject);
    }
};

I'm simply creating a PIXI Graphics object, drawing a rectangle and then adding the Graphics object as a child to my PIXI Container.  The render loop simply calls render on the PIXI Container, of course thus rendering all the Container's children as well.

In the CanvasRenderer this works exactly as expected, a 32x32 randomly colored rectangle being drawn at a random point (the x and y coordinates are randomly generated).  In the WebGLRenderer however nothing happens at all, they are never rendered despite all the same processes seemingly occurring when I step through the code (might have missed something).  Everything else that should be rendered displays properly.

Any idea what's up here?  Was there something specific to Graphics objects that changed which could be causing this to stop working in pixi v4?

Link to comment
Share on other sites

10 hours ago, Exca said:

Beginfill should be beginFill(color, 1); if you want solid fill. Alpha value is float from 0 to 1.

You should also call endFill.

None of those should block the drawing though.

Seems like from the Pixi Graphics example the lineStyle function should be called in Pixi v4.  When I added that function call to my graphics setup it started working.

var PlayerObject = function(uniqueId, world, x, y, velx, vely, clientPlayerObj) {
    // ...

    var color = Math.floor(Math.random() * 0xFFFFFF);
    this.renderObject = new PIXI.Graphics();
    this.renderObject.beginFill(color, 0xFF);
    this.renderObject.lineStyle(1, color, 0xFF);
    this.renderObject.drawRect(x * 16, y * 16, 32, 32);
    this.renderObject.endFill();

    // ...
};

Also added the endFill call as suggested - this wasn't what fixed the issue to clarify though - it was definitely the lineStyle call that fixed the issue.

Thanks for the suggestions, pointing out that the alpha is from 0-1 actually solved a related issue I had (shapes were appearing white instead of the random color I assigned).  Hadn't had a chance to look at that yet but now I don't have to!

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