ageibert 4 Report post Posted November 19, 2014 I got a game class and various enemy classes.e.g. a class BasicGame.Enemy_1 = function(){ this.name = "Enemy_1"; this.hp = 10;};and BasicGame.Enemy_2 = function(){ this.name = "Enemy_2"; this.hp = 330;};in both classes sprite/image properties are also set for a game sprite to be created from these informations now in my game i want to collision detect my player and instances of the above enemies (1-n)for this i think i need a "group" of enemies, which can be achieved withthis.enemies = game.add.group();so that i don't have to check each enemy instance collision on it's own.afterwards i'd like to add various enemy instances to this group and display them. the problem is, that only sprite/display objects could be added to groups.but when i only add the sprites, all my properties, like hitpoints, damage, aso. cant get read from the sprite itself.i thought that i could write a helper function to add all needed properties from the class to the sprite, but i didn't find a method "addProperty" for sprites (like there is one for groups - "setProperty") what's the best way to set the needed properties, which could be read from colliding objects aso.? Quote Share this post Link to post Share on other sites
Sam 12 Report post Posted November 20, 2014 Adding a property is easy as:this.existingEnemySprite.property = 20;this.existingEnemySprite.name = "enemy01";Collision with group goes:game.physics.arcade.collide( this.player, this.yourGroup, this.collisionFunc);and your function for different enemyTypes:collisionFunc: function( _player, _enemy){ if (_enemy.name = "enemy01"){ // ... do for enemy 01 }} Quote Share this post Link to post Share on other sites
rvizcaino 6 Report post Posted November 20, 2014 A useful function is setAll, setAll(key, value, checkAlive, checkVisible, operation, force)it sets properties of all children of group even it they do not exists, take a look at http://docs.phaser.io/Phaser.Group.html#setAll) Quote Share this post Link to post Share on other sites
ageibert 4 Report post Posted November 24, 2014 Than you both for your answers. This helped me a lot Quote Share this post Link to post Share on other sites