DanAmador Posted July 20, 2015 Share Posted July 20, 2015 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 Link to comment Share on other sites More sharing options...
rich Posted July 21, 2015 Share Posted July 21, 2015 brickMaze.create(tempBrick);Should be:brickMaze.add(tempBrick);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. shohan4556 and Tilde 2 Link to comment Share on other sites More sharing options...
Recommended Posts