Jump to content

Group.callAll() kills game


bborncr
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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

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)

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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