Aperosuz Posted February 29, 2016 Share Posted February 29, 2016 Hi I'm working on a game with phaser 2.4.4 and I have 2 problems with my collide (this 2 line is at the end of my upgrade): this.physics.arcade.collide(this.shield, this.bullet, this.Reditum(this.shield, bullet, enemy)); this.physics.arcade.collide(this.boat, this.bullet, this.checkCollisions()); My first problems, when I start the game, he go in the Reditum function before any collision between the shield and the bullet, so he crash quickly because he can't find the enemy or the bullet... My second problems, came after have put this 2 lines in my function enemyshot (My goal was to set available the collision detection only if they have already shot a bullet), the game don't crash but the collision don't work, my bullet cross my shield and my boat without any action. Here you can find how my shield and my boat were created (i can move the two with WASD and move the shield at the top, bot, left and right with arrows keys): setupPlayer: function() { this.boat = this.add.sprite(505, 325 , 'boat'); this.health = 3; this.boat.anchor.setTo(0.5, 0.5); this.physics.arcade.enable(this.boat); this.boat.body.immovable = true; this.shield = this.add.sprite(this.boat.x , this.boat.y + 60 , '1'); this.shield.anchor.setTo(0.5, 0.5); this.physics.arcade.enable(this.shield); this.shield.body.collideWorldBounds = true; this.shield.body.immovable = true; }, And here how my bullet were created : this.nbrbullet = 100; // Add an empty sprite group into our game this.bulletPool = this.add.group(); // Enable physics to the whole sprite group this.bulletPool.enableBody = true; this.bulletPool.physicsBodyType = Phaser.Physics.ARCADE; this.bulletPool.createMultiple(this.nbrbullet, 'bullet'); // Sets anchors of all sprites this.bulletPool.setAll('anchor.x', 0.5); this.bulletPool.setAll('anchor.y', 1); // Automatically kill the bullet sprites when they go out of bounds this.bulletPool.setAll('outOfBoundsKill', true); this.bulletPool.setAll('checkWorldBounds', true); this.nextShotAt = 500; And here how they are shot: var bullet = this.bulletPool.getFirstExists(false) if (this.time.now > this.nextShotAt && this.nbrbullet > 0) { bullet.reset(enemy.x, enemy.y); bullet.body.collideWorldBounds = true; bullet.body.bounce.setTo(1, 1); if(enemy.x == 35){ bullet.body.velocity.x = 200; } if(enemy.y == 35){ bullet.body.velocity.y = 200; } if(enemy.x == 975){ bullet.body.velocity.x = -200; } if(enemy.y == 615){ bullet.body.velocity.y = -200; } } I hope someone have an idea, if you think the problems come another place, ask me !! Thanks you Link to comment Share on other sites More sharing options...
drhayes Posted February 29, 2016 Share Posted February 29, 2016 In your call to collide you are not passing your collide handler, you are calling it. Don't include the parenthesis after the name of your collide callback, e.g. "this.checkCollisions" instead of "this.checkCollisions()". Link to comment Share on other sites More sharing options...
Aperosuz Posted March 1, 2016 Author Share Posted March 1, 2016 I have just try this solution, but it don't work, i have the same problems, my game don't go in the two function... But thank you anyway Link to comment Share on other sites More sharing options...
drhayes Posted March 1, 2016 Share Posted March 1, 2016 Do you have a running example that has this problem somewhere? Link to comment Share on other sites More sharing options...
Aperosuz Posted March 2, 2016 Author Share Posted March 2, 2016 I'm sorry, I 'm working locally but if you want I put the full code in attachment ... (I don't think you can run it because i have other file but it's only presentation, nothing really important) Game2.js Link to comment Share on other sites More sharing options...
drhayes Posted March 2, 2016 Share Posted March 2, 2016 Well, in your Reditum function you're colliding the enemy and bullet again. And the arguments to your Reditum function aren't right for a collision handler; they only have two arguments, not three. You're doing the thing where you call "this.backSuccess" instead of passing it to the collision function. That's probably why this.enemy is null. Collision handlers only take two arguments. Link to comment Share on other sites More sharing options...
Recommended Posts