Jump to content

Accessing properties of individual children within a group?


Amawuff
 Share

Recommended Posts

Maybe I'm just overlooking it or not understanding the documentation properly, but what is the easiest way to access the property of a child in a group?  

game_state.main.prototype = {    preload: function() { 		// Function called first to load all the assets		this.game.load.image('coil','assets/coil.png')    },    create: function() {     	// Fuction called after 'preload' to setup the game      	 this.game.stage.backgroundColor = '#2d2d2d';      	//style for text    	var style= { font: "15px Helvetica", fill: "#ffffff"};    	//make coils group    	this.coils = game.add.group();    	this.coils.createMultiple(2, 'coil');    	this.add_coil(100, 100);    	this.add_coil(100, 400);    },        update: function() {		// Function called 60 times per second		//coils collide with eachother, avoids overlap.		this.game.physics.collide(this.coils);    },    add_coil: function(x,y) {    	//Get the first dead coil of our group    	var coil = this.coils.getFirstDead();    	//Set the initial position of the coil    	coil.reset(x, y);    	//change physics body to circle so its edges are detected.    	coil.body.setCircle(25);    	//set initial coil properties    	coil.charge = 0;    	coil.chargeRate = 2;    	coil.chargeMax = 100;    	coil.chargeMin = 0;    	//make coils draggable    	coil.inputEnabled = true;        coil.input.enableDrag(true);    },};

for example if I wanted to pull the value of a child coil's  charge how would i do that?

 

 

Link to comment
Share on other sites

You could actually use a cursor for this:

    /**    * The cursor is a simple way to iterate through the objects in a Group using the Group.next and Group.previous functions.    * The cursor is set to the first child added to the Group and doesn't change unless you call next, previous or set it directly with Group.cursor.    * @property {any} cursor - The current display object that the Group cursor is pointing to.    */
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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