Pixi.js: setBackgroundColor?

Created on 11 May 2015  ·  12Comments  ·  Source: pixijs/pixi.js

Hello,

Is there a replacement for stage.setBackgroundColor in v3?

Most helpful comment

To see the effect you need to call render method of the renderer like this (I changed the color to red to make it more obvious):

var renderer = PIXI.autoDetectRenderer(256, 256, {antialiasing: false, transparent: false, resolution: 1});
    document.body.appendChild(renderer.view);
    renderer.backgroundColor = 0xff0000;

    var scene = new PIXI.Container();

    var render = function() {
        renderer.render(scene);
        requestAnimationFrame(render);
    }

    render();

Here is the working code with PIXI 3.0.3: http://miriti.github.io/pixi-background/

All 12 comments

Hey, @kittykatattack !
Try this:

renderer = new PIXI.WebGLRenderer(800, 600);
renderer.backgroundColor = 0x061639;

Thank you!
Maybe I'm losing my mind (very possible!!) - but that doesn't work for me.
Your code produces a blank canvas on my system (I'm on v3.0.3)

Also, backgroundColor isn't a property of the renderer object, according the current API docs?
Here's the code I'm currently using, which just produces a standard black WeGL context.

var renderer = PIXI.autoDetectRenderer(256, 256, {antialiasing: false, transparent: false, resolution: 1});
document.body.appendChild(renderer.view);
renderer.backgroundColor = 0x061639;

To see the effect you need to call render method of the renderer like this (I changed the color to red to make it more obvious):

var renderer = PIXI.autoDetectRenderer(256, 256, {antialiasing: false, transparent: false, resolution: 1});
    document.body.appendChild(renderer.view);
    renderer.backgroundColor = 0xff0000;

    var scene = new PIXI.Container();

    var render = function() {
        renderer.render(scene);
        requestAnimationFrame(render);
    }

    render();

Here is the working code with PIXI 3.0.3: http://miriti.github.io/pixi-background/

Thanks for your help, that works!

How come this can't be seen in the documentation @miriti ? I searched for this for ages before turning to the issues!

@unwitting good question! I don't know.. I just looked it up in the code. For some reason it hasn't got a doc: https://github.com/GoodBoyDigital/pixi.js/blob/master/src/core/renderers/SystemRenderer.js#L148

@miriti PRd :)

Fixed in 4827cea4bfd4af99bb363c2230da1393ed8221c4

Have you guys experienced behavior where there's a flash of black background before your new backgroundColor kicks in? I'm in ClojureScript-land, so I don't have a pastebin handy, but I'm basically doing what you'd expect - creating an autoDetectRenderer [except I'm specifying a {view: a-preexisting-canvas-element} optional argument rather than appendChilding it directly], then setting its .backgroundColor to 0xFFFFFF. And I'm seeing like a 0.5s flash of black background before my .backgroundColor kicks in.

Am I doing something idiotic / is this a well-known issue with an obvious fix? Thanks!

@jrheard Render directly after defining your scene/stage will fix the problem with a black flash. For example:

var renderer = PIXI.autoDetectRenderer(width, height);  
renderer.backgroundColor = 0xFF0000;  
var stage = new PIXI.Container();  
renderer.render(stage);  
[...]

Instead of

var renderer = PIXI.autoDetectRenderer(width, height);  
renderer.backgroundColor = 0xFF0000;  
var stage = new PIXI.Container();  
[...]  
renderer.render(stage);

You probably want to do it multiple times:

var renderer = PIXI.autoDetectRenderer(width, height);  
renderer.backgroundColor = 0xFF0000;  
var stage = new PIXI.Container(); 
renderer.render(stage);
[...]  
renderer.render(stage);

sorry for the delayed response - this fixed my issue. thanks!

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings