Jump to content

bring to front sprite vs graphics


espace
 Share

Recommended Posts

hi,

i would know how to specify the order of element. I want that my var "pap" to front of my rectangles. how do you that ?

thanks

 

var game = new Phaser.Game(w, h, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });

    function preload() {

    game.load.image('paper', 'paper.png');

    }

var pap
var background =[];


function create() {

//var paper=drawPaper(1,4,90,w4,0-4*90)

    var hud = "level";
    var style = { font: "65px Luckiest Guy", fill: white, align: "center" };
    var t = game.add.text(game.world.centerX-300, 0, hud, style);


    background.opponent=new Phaser.Rectangle(0,0,w2,h);
    background.player=new Phaser.Rectangle(w2,0,w2,h);
    background.table=new Phaser.Rectangle(0,h2,w,h);
    background.eclairci=new Phaser.Rectangle(0,h2+h*.3,w,h*.3);
    pap= game.add.sprite(200, 0, 'paper');


}

function update() {

}

function render() {

game.debug.geom(background.opponent, red);
game.debug.geom(background.player, blue);
game.debug.geom(background.table,black);
game.debug.geom(background.eclairci,white);
pap.bringToTop()
}

 

Link to comment
Share on other sites

There's a few problems here.

Don't call "bringToTop" in your render method; it's really only meant to be called once to position your display object. Maybe just do it after create.

Phaser.Rectangle does not represent a rectangle that exists on the screen. It's not meant to be drawn. Using debug methods is fine, but not good for a final game. You're better off drawing a rectangle as a sprite and using its tint property instead.

Link to comment
Share on other sites

I found graphics to be really slow in rendering, so I would recommend drawing the rectangle to bitmapdata then use the bmd as a sprite and then sort out the layers. Operations are much easier on sprites then on the graphics.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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