27thColt Posted February 12, 2016 Share Posted February 12, 2016 So I am using Ninja physics for the first time for a fighting game, I figured Ninja physics would be most useful for the game. But I need help, I keep getting this error: Uncaught TypeError: Cannot read property 'x' of undefined c.Physics.Ninja.AABB.collideAABBVsAABB @ phaser-ninja-physics.min.js:19 playState.update @ play.js:63 c.StateManager.update @ phaser-ninja-physics.min.js:6 c.Game.updateLogic @ phaser-ninja-physics.min.js:8 c.Game.update @ phaser-ninja-physics.min.js:8 c.RequestAnimationFrame.updateRAF @ phaser-ninja-physics.min.js:13 window.requestAnimationFrame.forceSetTimeOut._onLoop @ phaser-ninja-physics.min.js:13 I only get the error when I include the function collideAABBVsAABB() in my update(). Honestly, I don't know why. Here is the code: playState = { preload:function() { game.load.image("player1", "assets/img/player1.png"); game.load.image("player2", "assets/img/player2.png"); game.load.image("ground", "assets/img/ground.png"); }, //creates everything create:function() { //Players 1 and 2 this.player1 = game.add.sprite(this.game.width / 2 - 64, this.game.height / 2, "player1"); this.player2 = game.add.sprite(this.game.width / 2 + 64, this.game.height / 2, "player2"); this.ground = game.add.sprite(0, this.game.height - 91, "ground"); this.player1.scale.setTo(2, 2); this.player2.scale.setTo(2, 2); this.game.time.desiredFps = 30; //START OF PHYSICS this.game.physics.startSystem(Phaser.Physics.NINJA); this.game.physics.ninja.gravity = 1; this.game.physics.ninja.setBoundsToWorld(); this.game.physics.ninja.enableAABB([this.player1, this.player2, this.ground]); this.player1.body.friction = 0; this.player2.body.friction = 0; this.ground.body.friction = 0; this.player1.body.collideWorldBounds = true; this.player2.body.collideWorldBounds = true; this.ground.body.collideWorldBounds = true; this.player1.body.gravityScale = 1; this.player2.body.gravityScale = 1; this.ground.body.gravityScale = 0; this.player1.body.bounce.y = 0.2; this.player2.body.bounce.y = 0.2; this.player1.body.immovable = true; this.player2.body.immovable = true; this.ground.body.immovable = true; //END OF PHYSICS //key capturing this.game.input.keyboard.addKeyCapture([ Phaser.Keyboard.UP, Phaser.Keyboard.DOWN, Phaser.Keyboard.LEFT, Phaser.Keyboard.RIGHT, Phaser.Keyboard.SPACEBAR]); }, //main game loop update:function() { this.player2.body.aabb.collideAABBVsAABB(this.ground); this.player1.body.aabb.collideAABBVsAABB(this.ground); this.keyPress(); }, //Updates for Key Presses keyPress:function() { //Player 1 if (this.input.keyboard.isDown(Phaser.Keyboard.A)) { //left this.player1.body.moveLeft(40); } else if (this.input.keyboard.isDown(Phaser.Keyboard.D)) { //right this.player1.body.moveRight(40); } else if (this.input.keyboard.isDown(Phaser.Keyboard.W) && this.player1.body.touching.down) { this.player1.body.moveUp(400); } //Player 2 if (this.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { //left this.player2.body.moveLeft(40); } else if (this.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { //right this.player2.body.moveRight(40); } else if (this.input.keyboard.isDown(Phaser.Keyboard.UP) && this.player2.body.touching.down) { this.player2.body.moveUp(400); } } }; Link to comment Share on other sites More sharing options...
WombatTurkey Posted February 13, 2016 Share Posted February 13, 2016 AFAIK, use P2 Physics, ninja is dead and full of bugs atm. Link to comment Share on other sites More sharing options...
27thColt Posted February 13, 2016 Author Share Posted February 13, 2016 Hmm really? Would anyone else like to confirm this just to make sure? I kinda don't want to use P2 if I don't have to. Link to comment Share on other sites More sharing options...
27thColt Posted February 14, 2016 Author Share Posted February 14, 2016 Anybody? Link to comment Share on other sites More sharing options...
Recommended Posts