Jump to content

Background rendering on top of other objects


Recommended Posts

Hi. I'm having a problem with my background image that I haven't really seen anyone else have. For whatever reason, even though it is the first sprite loaded in the game, my background sprite will load over top of all my other objects. I've been looking and looking but I haven't found a solution that fits with my code or works.

I have a Level object that contains all of the data for the level in a 2d-array of tiles. Because levels will be randomly generated, and the backgrounds may be different level to level, I load the background image in said object. In the constructor for the object, I have...


    this.backgroundSprite = null;        switch(this.type){        case TESTLEVEL:            this.backgroundSprite = game.add.sprite(0,0, 'bluesky');            break;        default:            console.error('invalid level type!');    }        this.backgroundSprite.width = this.width*TILE_WIDTH;    this.backgroundSprite.height = this.height*TILE_HEIGHT;

Later, in the level object, I create each tile and eventually add the entities. However, no matter what I do, the background shows up over top of all of those things. Everything except the weapons - which aren't equipped and added to the world until later in the create function.

What do I do?

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...