coach Posted January 14, 2017 Share Posted January 14, 2017 Hi everyone, i'm new with phaser. I'm reading the book Discover Phaser and i can't let the player with the walls I hope in your help. Link to comment Share on other sites More sharing options...
nuane Posted January 14, 2017 Share Posted January 14, 2017 Change: this.walls = game.add.group(); to this.walls = game.add.physicsGroup(); this.walls needs to be defined as a physics group to allow all the walls to interact with the player physics body squilibob 1 Link to comment Share on other sites More sharing options...
coach Posted January 15, 2017 Author Share Posted January 15, 2017 Thanks nuane, I tried as you have indicated, but the problem persists. There is no other error in the code? Because not work either: if (this.cursor.up.isDown && this.player.body.touching.down) { Link to comment Share on other sites More sharing options...
nuane Posted January 16, 2017 Share Posted January 16, 2017 //simple spelling error this.walls.setAll('body.immovable', true); //changed from game.add.sprite to this.walls.create since mid1Wall is being added to this.walls //physics group var mid1Wall = this.walls.create(game.width/5*1, game.height/6*2 -40, 'wall'); changing these allows the player body sprite to interact with the walls physics group. The last parameter for the sprite constructor is the sprite's frame, but there are other ways to add multiple sprites to a physics group. This should allow this.player.body.touching.down to return true, allowing your conditional to proceed (but you should always test and debug if your unsure Also check out these resources for reference: http://phaser.io/docs/2.6.2/Phaser.Sprite.html https://phaser.io/examples/v2/arcade-physics/body-enable#gv Link to comment Share on other sites More sharing options...
coach Posted January 16, 2017 Author Share Posted January 16, 2017 I founded the error. I miss 1 parameter (frame) between key and group. Link to comment Share on other sites More sharing options...
Recommended Posts