espace Posted July 14, 2016 Share Posted July 14, 2016 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 More sharing options...
drhayes Posted July 14, 2016 Share Posted July 14, 2016 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. mattstyles 1 Link to comment Share on other sites More sharing options...
symof Posted July 14, 2016 Share Posted July 14, 2016 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 More sharing options...
espace Posted July 14, 2016 Author Share Posted July 14, 2016 Sorry i'm a pseudo newbie i come from .lua have you an example code or a link to work with layers and sprites ? Link to comment Share on other sites More sharing options...
symof Posted July 14, 2016 Share Posted July 14, 2016 17 minutes ago, espace3d said: Sorry i'm a pseudo newbie i come from .lua have you an example code or a link to work with layers and sprites ? http://phaser.io/examples/v2/groups/group-as-layer You need sprites not graphics, so that means you need to use bmd. http://phaser.io/examples/v2/category/bitmapdata Link to comment Share on other sites More sharing options...
espace Posted July 14, 2016 Author Share Posted July 14, 2016 Thanks Link to comment Share on other sites More sharing options...
Recommended Posts