Bring graphics on top of dynamically added sprite in Phaser

I add Sprites dynamically using a time event. I can’t find a way to bring new graphics (filled rectangle) over the created sprites.

Sprints are always on top

create()
{
  var graphics = game.add.graphics(0, 0);
  graphics.beginFill(0xFFFF0B);
  graphics.drawRect(0, 0, windowWidth, 70);
  graphics.endFill();
  timer = game.time.events.loop(1500, addSprite, this);
}

addSprite()
{  
  sprite= game.add.sprite(20, 30, 'sprite');
}

Any help?

+4
source share
1 answer

Phaser graphics are just standard display list objects such as Sprites. They are added to the world by default (like sprites), and you can move them using Phaser.Group level commands, such as moveUp, moveDown, bringToTop, etc. Here you will find the full list: http://docs.phaser.io/Phaser.Group.html

, Sprite , Graphics :

game.world.bringToTop(graphics);

. var graphics, , .

+9

Source: https://habr.com/ru/post/1540124/


All Articles