Jump to content

Overlapping group and sprite problem


kotvaska
 Share

Recommended Posts

Hello, everybody!

 

Is there a possibility to overlap a sprite and one item of group?

If you assign a key (usually by default it is the sprite's name in the preload) to each item in that group you might accomplish that.

 

For instance

//in create()var sprite = game.add.sprite(0,0,'sprite'); //key here is sprite which refers to whatever you assigned in the preload()var group = game.add.group();var item1 = game.add.sprite(50,50,'item1'); //key is item1var item2 = game.add.sprite(100,100,'item2'); //key is item2group.add(item1);group.add(item2);//in update()group.forEach(function(item){  if(item.key=='item2')    game.physics.arcade.overlap(sprite, item, callBack, null, this);})function callBack(sprite,item){  item.kill();//kills item2 when it collides with sprite}
Link to comment
Share on other sites

Thank you!

 

 

If you assign a key (usually by default it is the sprite's name in the preload) to each item in that group you might accomplish that.

 

For instance

//in create()var sprite = game.add.sprite(0,0,'sprite'); //key here is sprite which refers to whatever you assigned in the preload()var group = game.add.group();var item1 = game.add.sprite(50,50,'item1'); //key is item1var item2 = game.add.sprite(100,100,'item2'); //key is item2group.add(item1);group.add(item2);//in update()group.forEach(function(item){  if(item.key=='item2')    game.physics.arcade.overlap(sprite, item, callBack, null, this);})function callBack(sprite,item){  item.kill();//kills item2 when it collides with sprite}
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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