mtkachenko Posted June 11, 2016 Share Posted June 11, 2016 I added sprite to game. Then I created new Rectangle. Problem: when I drag sprite it's under the rectangle. I tried to add sprite to separate group and call bringToTop but it doesn't work. How to "bringToBottom" rectangle in this case? Link to comment Share on other sites More sharing options...
super_frog Posted June 12, 2016 Share Posted June 12, 2016 You can add two groups. One for sprite, other for graphic. And then bringToTop the sprite group. Something like var gs = game.add.group(); var gg = game.add.group(); var s = game.add.sprite(10, 10, 'sprite'); var g = game.add.graphics(0, 0); g.beginFill(0xFFFFFF, 1); g.drawRect(10, 10, 20, 20); g.endFill(); gg.add(g); gs.add(s); game.world.bringToTop(gs); Link to comment Share on other sites More sharing options...
mtkachenko Posted June 12, 2016 Author Share Posted June 12, 2016 Yes, it works. I want to change color of rectangle when sprite (which is dragging) is above the rectangle. I use game.debug.geom(rect,'#fff') but after that rectangle is on top and hide sprite. game.world.bringToTop(spriteLayer) doesn't help. Link to comment Share on other sites More sharing options...
super_frog Posted June 12, 2016 Share Posted June 12, 2016 game.debug should be used for debugging only, as the name states. You're better off using game.add.graphics and you don't need another method just to color it. When changing the graphics color, you should destroy the old one and draw a new one at the same location, with different color and add it to the same group. mtkachenko 1 Link to comment Share on other sites More sharing options...
mtkachenko Posted June 12, 2016 Author Share Posted June 12, 2016 Thank this approach works. Now I understand how to work with graphics properly. Link to comment Share on other sites More sharing options...
super_frog Posted June 13, 2016 Share Posted June 13, 2016 You're welcome. Link to comment Share on other sites More sharing options...
Recommended Posts