Jump to content

Rectangle and sprite overlapping


mtkachenko
 Share

Recommended Posts

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

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

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

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.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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