Jump to content

forEach item in array, set x position?


casey
 Share

Recommended Posts

I have an array of items (stored as strings) I am displaying on screen as sprites, in an inventory. 

I want to update my array when an item is removed from my inventory, so I want to write a function that resets the x position of the objects. I can log out the right object and the right index value, but I can't seem to set the position of the object using this function. Any ideas ? 

 

example: inventory('key', 'rock', 'sword', 'note');

	resetSlots: function() {
	//for every item in inventory, slot position is index number. 
      inventory.forEach(function(item, index){
		 item.x = index * 150;
		  console.log(item.x); //this returns "undefined"
	})  },

 

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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