phaserjs / phaser

Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
https://phaser.io
MIT License
36.94k stars 7.08k forks source link

PhysicGroup Childs dont get Body #565

Closed BurnedToast closed 10 years ago

BurnedToast commented 10 years ago

When I use

bullets = game.add.physicsGroup(Phaser.Physics.P2JS)
bullets.createMultiple(10, 'plasmabullet')

The created dont have a body, because of line 111 in Group

this.enableBody = false;

should be

this.enableBody = enableBody ;

But changing that line may have some other impacts!?

gabehollombe commented 10 years ago

Can reproduce.

I've noticed this also affects constructing groups where you pass enableBody to the normal group constructor.

Example code:

    // This doesn't work.
    var physGroup = game.add.physicsGroup(Phaser.Physics.ARCADE);
    var physGroupChild = physGroup.create(0, 0, 'bullet')
    if (physGroupChild.body === null) {
        console.error("Expecting physGroupChild.body to not be null but is null.")
    }

    // Neither does this.
    var groupWithPhysicsInConstructor = game.add.group(game.world, 'my group', false, true, Phaser.Physics.ARCADE)
    var groupWithPhysicsChild = groupWithPhysicsInConstructor.create(0, 0, 'bullet')
    if (groupWithPhysicsChild.body === null) {
        console.error("Expecting groupWithPhysicsChild.body to not be null but is null.")
    }

    // Obviously, this will.
    var groupWithoutPhysicsInConstructor = game.add.group()
    groupWithoutPhysicsInConstructor.enableBody = true
    groupWithoutPhysicsInConstructor.physicsBodyType = Phaser.Physics.ARCADE
    var groupWithoutPhysicsChild = groupWithoutPhysicsInConstructor.create(0, 0, 'bullet')
    if (groupWithoutPhysicsChild.body === null) {
        console.error("Expecting groupWithoutPhysicsChild.body to not be null but is null.")
    }

Example Fiddle here: http://jsfiddle.net/MUa38/2/

photonstorm commented 10 years ago

Ah yes, if you look the 'enableBody' parameter got assigned to the enableBodyDebug value by mistake. Fixed in dev.

gabehollombe commented 10 years ago

@photonstorm fast fixing! =-) Are the example Fiddles too much in this case? I'm just trying to follow the contrib guidelines.

photonstorm commented 10 years ago

Sometimes they are really useful. Othertimes it's such an obvious error they're too much. Sadly I guess it's not easy for you to tell which :) You could start by just describing the problem, if I can't work it out I'll ask for more info / example. Should save time for you?

gabehollombe commented 10 years ago

@photonstorm Makes sense. Should we update the contribution guidelines to say something like 'If it's a simple bug report, use your best judgement to decide if a demo example is needed' ?

photonstorm commented 10 years ago

Agreed, I've added something to that effect in the guide.