Why isn't my collision working?

Recommended Posts

Good day, I'm trying to make a small game to get to know Phaser js but I'm having problems implementing collision detection with groups.
Once the maze is created and stored in a bi-dimensional array I fill the screen up with sprites using the following function(as I can't use physics with primitive graphics, if i'm not mistaken)

  //makes sprites out of the maze  function maekMaezDawg() {    console.log('hello frmo maekMaezDawg()');    for (var i = 0; i < mazeHeight; i++) {      for (var j = 0; j < mazeWidth; j++) {        if (maze[i][j] === 0) {          var tempBrick = game.add.sprite(j * tileSize, i * tileSize, 'brick');          tempBrick.scale.setTo(tileSize / 64, tileSize / 64);          brickMaze.create(tempBrick);        }      }    }    mazeGraphics.clear();  } 

But the collision isn't detected between my player object and the brickMaze group.

I'm using the following line in the update function 

game.physics.arcade.collide( brickMaze,player, collisionHandler)

The collision handler function is only supposed to print out a log confirming the collision, yet it never fires up.


Help would be greatly appreciated.


The full code can be found in the following github repo https://github.com/DanAmador/RandomMazeGame/tree/master/Game

Share this post

Link to post
Share on other sites

Should be:


As the sprite already exists and you're trying to add it to the Group. 'create' will create a new sprite in the group, but try to use 'tempBrick' as its x coordinate - which could have some interesting results.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.