j0hnskot Posted June 7, 2014 Share Posted June 7, 2014 Hello! I was trying to change the size of each sprite in the group and i used this: this.spikes.callAll('body.setSize',null,10,10,10,10);it resulted to an error : Uncaught TypeError: Cannot read property 'setTo' of undefined phaser.js:51065Uncaught TypeError: Cannot read property 'x' of null phaser.js:50385but when i did this :this.spikes.forEach(function(sprite){ sprite.body.setSize(10,10,10,10); },this);It worked correctly. Where is my mistake? Why the first way does not work for me? Link to comment Share on other sites More sharing options...
joerrey Posted July 11, 2014 Share Posted July 11, 2014 Got the same problem. Any solution out there? Link to comment Share on other sites More sharing options...
j0hnskot Posted July 11, 2014 Author Share Posted July 11, 2014 I don't really remember how i solved it, but try something like :this.spikes.callAll('body.setSize', ' body' ,10,10,10,10); joerrey 1 Link to comment Share on other sites More sharing options...
joerrey Posted July 11, 2014 Share Posted July 11, 2014 That's it! Link to comment Share on other sites More sharing options...
lewster32 Posted July 11, 2014 Share Posted July 11, 2014 I'd in almost every case prefer the forEach method, as if I wanted to add functionality I can just drop it into the callback, rather than rewriting the whole statement. clark 1 Link to comment Share on other sites More sharing options...
mcuz Posted November 16, 2016 Share Posted November 16, 2016 this.spikes.callAll('body.setSize', ' body' ,10,10,10,10); this works because you need to specify the context for your call, in this case its the body object. see the following https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call Link to comment Share on other sites More sharing options...
Recommended Posts