Ansimuz Posted May 1, 2017 Share Posted May 1, 2017 Hi, I'm learning phaser and got this issue. The collision between the player and the map is not working since I moved the player to its own file (player.js) as an object Im calling this in the update function on the play.js game.physics.arcade.collide(this.player.sprite, this.layer); I'm creating the tile map in the play.js createWorld: function () { this.map = game.add.tilemap('map'); this.map.addTilesetImage('tileset'); this.layer = this.map.createLayer('Tile Layer 1'); this.layer.resizeWorld(); this.map.setCollision(1); }, Here's the player.js file function player() { this.preload = function () { }; this.create = function () { this.sprite = game.add.sprite(game.width / 2, game.height / 2, 'atlas', 'player01'); this.sprite.anchor.setTo(0.5, 0.5); game.physics.arcade.enable(this.sprite); this.sprite.body.gravity.y = 500; this.cursor = game.input.keyboard.createCursorKeys(); }; this.update = function () { }; } Originally the collision worked well before putting the player in a different file, but I can't make the collision work now. Link to comment Share on other sites More sharing options...
Kseiver Posted May 1, 2017 Share Posted May 1, 2017 Do you use console in Browser test? You can put "console.log("any info");" inside update function, it shows theposition where exist any error, when it doesn't print. If it works before, you include any error, a position of code can be changed. Excuse my poor english. Link to comment Share on other sites More sharing options...
Ansimuz Posted May 2, 2017 Author Share Posted May 2, 2017 17 hours ago, Kseiver said: Do you use console in Browser test? You can put "console.log("any info");" inside update function, it shows theposition where exist any error, when it doesn't print. If it works before, you include any error, a position of code can be changed. Excuse my poor english. It doesn't throw any error. It just doesn't collide. the player goes thorugh as it there was not floor while falling. Link to comment Share on other sites More sharing options...
Kseiver Posted May 2, 2017 Share Posted May 2, 2017 Some errors doesn't display anything, just stops the execution of the code. When this occurs I only can discover the location of the problem with prints. Do you have the old version? If have, make the change and test for each step. if don't, try to modify to back to correct stage, and try step by step. It's boring, but ... it is one way. If you want me to test your code, post the URL. Link to comment Share on other sites More sharing options...
Ansimuz Posted May 2, 2017 Author Share Posted May 2, 2017 1 hour ago, Kseiver said: Some errors doesn't display anything, just stops the execution of the code. When this occurs I only can discover the location of the problem with prints. Do you have the old version? If have, make the change and test for each step. if don't, try to modify to back to correct stage, and try step by step. It's boring, but ... it is one way. If you want me to test your code, post the URL. Thanks Kseiver. Here's the url of the buggy game. http://ansimuz.com/phaser/first-game/ I cant see the issue. Seems like I'm not entering the parameters for game.physics.arcade.collide Correctly. game.physics.arcade.collide(this.player.sprite, this.layer); Link to comment Share on other sites More sharing options...
samme Posted May 2, 2017 Share Posted May 2, 2017 In `update` the `alive` test is wrong, it should be player.sprite.alive Link to comment Share on other sites More sharing options...
Kseiver Posted May 2, 2017 Share Posted May 2, 2017 When I test and don't include this line the character go throgh the wall. this.sprite.body.collideWorldBounds = true; In you file player.js Link to comment Share on other sites More sharing options...
Ansimuz Posted May 2, 2017 Author Share Posted May 2, 2017 4 hours ago, samme said: In `update` the `alive` test is wrong, it should be player.sprite.alive Ohh that solved the issue. It was a logic problem after all. the game.physics.arcade.collide never executed because of the alive condition. Thanks Samme. Link to comment Share on other sites More sharing options...
Recommended Posts