Togechi Posted May 14, 2017 Share Posted May 14, 2017 Hi there, I have been trying to setup a collision system in my rpg game but I have encountered this error. I'm trying to create a collision between the player and the collisionLayer. When I start the state I receive this error: map1State.js:55 Uncaught TypeError: Cannot read property 'collide' of undefined at map1State.update (map1State.js:55) at Phaser.StateManager.update (phaser.js:28633) at Phaser.Game.updateLogic (phaser.js:34992) at Phaser.Game.update (phaser.js:34935) at Phaser.RequestAnimationFrame.updateRAF (phaser.js:62702) at _onLoop (phaser.js:62685) Could someone please explain to me why this happens? Heres my code for the state var map1State = function(game) {}; map1State.prototype = { preload: function () { game.load.tilemap('map1', 'assets/mapcollide.json', null, Phaser.Tilemap.TILED_JSON); game.load.image('map1_set', 'assets/tilemap.png'); game.load.image('player', 'assets/player.png'); }, create: function () { map1 = game.add.tilemap('map1', 32, 32); map1.addTilesetImage('set_00','map1_set'); tilemapLayer = map1.createLayer('Tilemap'); collisionLayer = map1.createLayer('Collision'); game.world.setBounds(0, 0, 1280, 960); game.physics.startSystem(Phaser.Physics.P2JS); player = game.add.sprite(game.world.centerX, game.world.centerY, 'player'); game.physics.p2.enable(player); player.body.fixedRotation = true; cursors = game.input.keyboard.createCursorKeys(); game.camera.follow(player, Phaser.Camera.FOLLOW_LOCKON, 0.1, 0.1); }, update: function () { player.body.setZeroVelocity(); if (cursors.up.isDown) { player.body.moveUp(300) } else if (cursors.down.isDown) { player.body.moveDown(300); } if (cursors.left.isDown) { player.body.velocity.x = -300; } else if (cursors.right.isDown) { player.body.moveRight(300); } game.physics.P2JS.collide(player, collisionLayer); } }; Link to comment Share on other sites More sharing options...
Togechi Posted May 15, 2017 Author Share Posted May 15, 2017 Could someone please help me? Link to comment Share on other sites More sharing options...
samme Posted May 15, 2017 Share Posted May 15, 2017 On 5/14/2017 at 4:15 AM, Togechi said: map1State.js:55 Uncaught TypeError: Cannot read property 'collide' of undefined Look at line 55 of map1State.js. Probably that line is game.physics.P2JS.collide(player, collisionLayer); 'collide' of undefined means it's evaluating (undefined).collide(player, collisionLayer); In other words, game.physics.P2JS is undefined. Probably game.physics has no "P2JS" property. Link to comment Share on other sites More sharing options...
snowbillr Posted May 15, 2017 Share Posted May 15, 2017 samme is right, that property doesn't exist. The 3 properties I see that are available are `Arcade`, `Ninja`, and `P2` - http://devdocs.io/phaser/phaser.physics Link to comment Share on other sites More sharing options...
Togechi Posted May 15, 2017 Author Share Posted May 15, 2017 Thanks for pointing that out. Now it comes up with the error "Uncaught TypeError: game.physics.p2.collide is not a function map1state.js:55" Link to comment Share on other sites More sharing options...
Recommended Posts