Mizukage Posted October 21, 2015 Share Posted October 21, 2015 HTML<!DOCTYPE HTML><html><head> <meta charset="UTF-8" /> <title> </title> <script src="phaser.js"></script> <script src="game.js"></script></head><body> <div id="phaser"></div></body></html>game,js(function (Phaser) { _width = window.innerWidth; _height = window.innerHeight; var game = new Phaser.Game(_width, _height, Phaser.AUTO, '', { preload: preload, create: create, update: update }); function preload() { game.load.tilemap('MyTilemap', 'maps/firstMap.json', null, Phaser.Tilemap.TILED_JSON); game.load.image('tiles', "maps/terrain_atlas.png"); } var map; var layer; function create() { // Load the map. map = game.add.tilemap('MyTilemap'); map.addTilesetImage('tiles', 'tiles'); layer = map.createLayer('MyTerrain'); layer.resizeWorld(); layer.wrap = true; cursors = game.input.keyboard.createCursorKeys(); } function update() { if (cursors.left.isDown) { game.camera.x -= 8; } else if (cursors.right.isDown) { game.camera.x += 8; } if (cursors.up.isDown) { game.camera.y -= 8; } else if (cursors.down.isDown) { game.camera.y += 8; } }}(Phaser));And the problem is phaser.js:85874 Uncaught TypeError: Cannot read property '0' of undefined Link to comment Share on other sites More sharing options...
Mizukage Posted October 21, 2015 Author Share Posted October 21, 2015 Oh maybe its a problem with json map not with a code Link to comment Share on other sites More sharing options...
JakeCake Posted October 21, 2015 Share Posted October 21, 2015 You should get a stack tree with the error message if you are using Chrome or any other major browser with dev tools. That should tell you the exact line. I suspect either "Phaser.Tilemap.TILED_JSON" or problems with something you are trying to load. You are not defining cursors as a variable either, but that should not break the game, but you might want to do it for performance reasons. Link to comment Share on other sites More sharing options...
Recommended Posts