Jump to content

Killing sprites problem


Recommended Posts

I am having a problem with killing sprites using kill(). When I do I get the following error in the console on the next frame:

phaser.js:12282 Uncaught TypeError: Cannot read property 'neighbors' of undefined
IslandManager.split @ phaser.js:12282
World.internalStep @ phaser.js:13100
World.step @ phaser.js:12891
Phaser.Physics.P2.update @ phaser.js:85503
Phaser.Physics.update @ phaser.js:81556
Phaser.Game.updateLogic @ phaser.js:34768
Phaser.Game.update @ phaser.js:34703
Phaser.RequestAnimationFrame.updateRAF @ phaser.js:59420
_onLoop @ phaser.js:59404

I think this may be something to do with the fact that the sprite is connected to another sprite (a sensor) using createLockConstraint. I've tried killing the other sprite before and after - same problem. Killing either sprite and leaving the other - same problem. Both sprites are in groups. The kill() is done first thing in Update().

Both sprites are using P2 physics, and I'm using Phaser 2.4.6.

Any thoughts, or any troubleshooting steps I can take? I've been banging my head off this for a while!


Link to comment
Share on other sites

This isn't all the code, but it creates the bug. The problem is the lock constraint. Is there no way to kill a sprite that is locked to another sprite?

var game = new Phaser.Game(1024, 768, Phaser.AUTO, 'game', { preload: preload, create: create, update: update });
var clearBalls = false;

function preload() {
    game.load.image('redBall', 'assets/redBall.png');


function create() {
    balls = game.add.group();
    balls.enableBody = true;
    balls.physicsBodyType = Phaser.Physics.P2JS;
    sensors = game.add.group();
    sensors.enableBody = true;
    sensors.physicsBodyType = Phaser.Physics.P2JS;

function update() {
    if (clearBalls == true)
            balls.forEach(function(ball) {
            clearBalls = false;
function addBall() {
    var newBall = game.make.sprite(game.world.centerX, game.world.centerY, 'redBall');

    newBall.inputEnabled = true;
    newBall.events.onInputDown.add(destroyBalls, this);
    var sensor = game.make.sprite(game.world.centerX, game.world.centerY);
    sensor.body.data.shapes[0].sensor = true;
    game.physics.p2.createLockConstraint(newBall, sensor, [0, 0], 0);
function destroyBalls(ball)
    clearBalls = true;


Link to comment
Share on other sites


  • Recently Browsing   0 members

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