Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

What is wrong with my code?


Mizukage
 Share

Recommended Posts

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

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...