bborncr Posted February 14, 2017 Share Posted February 14, 2017 I am trying to adjust the physics body size of some bullets. bullets.createMultiple(20, 'bullet'); bullets.setAll('anchor.x', 0.5); bullets.setAll('anchor.y', 0.5); bullets.setAll('scale.x', 0.3); bullets.setAll('scale.y', 0.3); bullets.setAll('bounce.x', .5); bullets.setAll('bounce.y', .5); bullets.setAll('mass', 0.05); bullets.callAll('body.setSize',8,8,8,8); //this line kills the game When I add the final line with the callAll() method the game won't start. One example added two single quotes '' : bullets.callAll('body.setSize', '', 8,8,8,8); But that didn't work either. rroylance 1 Link to comment Share on other sites More sharing options...
rroylance Posted February 14, 2017 Share Posted February 14, 2017 25 minutes ago, bborncr said: I am trying to adjust the physics body size of some bullets. bullets.createMultiple(20, 'bullet'); bullets.setAll('anchor.x', 0.5); bullets.setAll('anchor.y', 0.5); bullets.setAll('scale.x', 0.3); bullets.setAll('scale.y', 0.3); bullets.setAll('bounce.x', .5); bullets.setAll('bounce.y', .5); bullets.setAll('mass', 0.05); bullets.callAll('body.setSize',8,8,8,8); //this line kills the game When I add the final line with the callAll() method the game won't start. One example added two single quotes '' : bullets.callAll('body.setSize', '', 8,8,8,8); But that didn't work either. createMultiple creates Phaser.Sprite objects, which do not have a physics body by default so 'body.setSize' is trying to call setSize on an undefined body. Unless you have set enableBody on the group first ? 'game won't start' and 'kills game' is not clear so I'm not sure, do you have any errors int he console ? var bullets = this.game.add.group(); bullets.enableBody = true; bullets.createMultiple .... .... .... Also the callAll should look like (the second parameter is a string denoting the context the function should be called in; behind the scenes the group converts your '' to null anyway, setting it to null is just more clear: https://github.com/photonstorm/phaser/blob/v2.6.2/src/core/Group.js#L1561) bullets.callAll('body.setSize', null, 8, 8, 8, 8); Link to comment Share on other sites More sharing options...
bborncr Posted February 14, 2017 Author Share Posted February 14, 2017 Thanks for the help! Yes, I do have the body enabled. When the game starts there is just a black screen. Below is the console error. If I comment out the callAll line the game runs. bullets = game.add.group(); bullets.enableBody = true; bullets.physicsBodyType = Phaser.Physics.ARCADE; bullets.createMultiple(20, 'bullet'); bullets.setAll('anchor.x', 0.5); bullets.setAll('anchor.y', 0.5); bullets.setAll('scale.x', 0.3); bullets.setAll('scale.y', 0.3); bullets.setAll('bounce.x', .5); bullets.setAll('bounce.y', .5); bullets.setAll('mass', 0.05); bullets.callAll('body.setSize',null, 8,8,8,8); Phaser v2.6.2 | Pixi.js | Canvas | WebAudio http://phaser.io ♥♥♥ phaser.js:87888 Uncaught TypeError: Cannot read property 'setTo' of undefined at Phaser.Sprite.setSize (phaser.js:87888) at Phaser.Group.callAll (phaser.js:33670) at Object.create (asteroids movement.js:49) at Phaser.StateManager.loadComplete (phaser.js:30083) at Phaser.Loader.finishedLoading (phaser.js:74233) at Phaser.Loader.processLoadQueue (phaser.js:74190) at Phaser.Loader.asyncComplete (phaser.js:74263) at Phaser.Loader.fileComplete (phaser.js:75120) at HTMLImageElement.file.data.onload (phaser.js:74522) asteroids movement.js:87 Uncaught TypeError: Cannot read property 'animations' of undefined at Object.update (asteroids movement.js:87) at Phaser.StateManager.update (phaser.js:30128) at Phaser.Game.updateLogic (phaser.js:36337) at Phaser.Game.update (phaser.js:36280) at Phaser.RequestAnimationFrame.updateRAF (phaser.js:61979) at _onLoop (phaser.js:61962) rroylance 1 Link to comment Share on other sites More sharing options...
rroylance Posted February 14, 2017 Share Posted February 14, 2017 Ah, all you need to do is change the callAll to use the body as the context; bullets.callAll('body.setSize', 'body', 8, 8, 8, 8); bborncr 1 Link to comment Share on other sites More sharing options...
bborncr Posted February 14, 2017 Author Share Posted February 14, 2017 That was it!! Thanks! rroylance 1 Link to comment Share on other sites More sharing options...
Recommended Posts