Zomdark Posted July 16, 2015 Share Posted July 16, 2015 Hi everyone, I'm new and I'm starting to learn Phaser developement, actually I'm following some example codes, but I got stuck on creating collision whith a Layer of Tiled, the error goes like this:create: function(){ this.map = this.game.add.tilemap('lvl1'); this.map.addTilesetImage('tiles_tiny_sample', 'gametiles'); this.backgroundlayer = this.map.createLayer('fondo'); this.blockedLayer = this.map.createLayer('Objetos'); this.map.setCollision([23,33], true, 'blockedLayer', false); //this.backgroundlayer.resizeWorld();Here is the preload phasepreload: function(){ this.loader = this.add.sprite(this.game.world.centerX, this.game.centerY, 'preloadbar'); this.loader.anchor.setTo(0.5); //this.loader.scale.setTo(3); this.load.setPreloadSprite(this.loader); this.load.tilemap('lvl1', 'lvl/lvl1.json', null, Phaser.Tilemap.TILED_JSON); this.load.image('gametiles', 'img/tiles_tiny_sample.png'); this.load.image('player', 'img/ball.png');},and I'm gettin Uncaught TypeError: Cannot read property 'height' of undefined when loading the 'game'. As this is much a test, the code is pretty simple, so I did not found anything in researching for this error, any advice would be nice Thanks by the way. pd: actually using Phaser min 2.3.0 Link to comment Share on other sites More sharing options...
drhayes Posted July 16, 2015 Share Posted July 16, 2015 For that error message, what line number does it give you? Is it somewhere in phaser.min.js? If so, you could use phaser.js instead and see where it's failing to get a better idea of what's wrong. Link to comment Share on other sites More sharing options...
Zomdark Posted July 16, 2015 Author Share Posted July 16, 2015 ty for the response, I tried just right now, the error happens on line 84039for (var y = 0; y < this.layers[layer].height; y++) { for (var x = 0; x < this.layers[layer].width; x++) { var tile = this.layers[layer].data[y][x]; if (tile && tile.index === index) { if (collides) { tile.setCollision(true, true, true, true); } else { tile.resetCollision(); } tile.faceTop = collides; tile.faceBottom = collides; tile.faceLeft = collides; tile.faceRight = collides; } }and I honestly have no clue on what's wrong, because if I comment the collision line on my Game.js, there is no error and the Tilemap loads w/o problems :/ Also getting same error with map.setCollisionBetween method Link to comment Share on other sites More sharing options...
Zomdark Posted July 16, 2015 Author Share Posted July 16, 2015 Ok, update time, honestly the error was so dumb but it could happen to any first-time phaser dev, so it goes as this: On the docummentation of the method u can findarg number,string,Phaser.TilemapLayer layer (optional) The layer to operate on. If not given will default to this.currentLayer.for the layer option, and since you create the layer assgning a key as followsthis.blockedLayer = this.map.createLayer('Objetos');one can naturally think that "blockedLayer" is the object key, but nope, the "Layer" object that the function really needs is the name of the layer on Tiled, so, rewriting to thisthis.blockedLayer = this.map.createLayer('Objetos');this.map.setCollision([23,33], true, 'Objetos', false);solves the issue Ty for your advice Drhayes kriket 1 Link to comment Share on other sites More sharing options...
Recommended Posts