Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Rectangle and sprite overlapping


Recommended Posts

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);




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


  • Recently Browsing   0 members

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