kotvaska Posted December 12, 2015 Share Posted December 12, 2015 Hello, everybody! Is there a possibility to overlap a sprite and one item of group? Link to comment Share on other sites More sharing options...
Batzi Posted December 12, 2015 Share Posted December 12, 2015 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} kotvaska 1 Link to comment Share on other sites More sharing options...
kotvaska Posted December 15, 2015 Author Share Posted December 15, 2015 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 More sharing options...
Batzi Posted December 15, 2015 Share Posted December 15, 2015 Thank you!You're welcome! If it solved your problem please mark it as "Answered" so that people know. :-) Skeptron 1 Link to comment Share on other sites More sharing options...
Recommended Posts