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

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