Jump to content

Uncaught SyntaxError: Unexpected token <


Todi
 Share

Recommended Posts

Hello,

 

So, I'm trying to do a little test with Phaser, loading an image in the canvas, but everytime the browser refresh this error occur:

Uncaught SyntaxError: Unexpected token <

Here is my code:

 

<!doctype html><html><head>    <meta charset="UTF-8" />    <title>Landmines ~ GrindSoft</title>    <script src="lib/phaser.js"></script></head><body>    <script type="text/javascript">        window.onload = function() {            var game = new Phaser.Game(800, 600, Phaser.AUTO, 'landmines', { preload: preload, create: create, update: update });            function preload() {                game.load.image('jabba', 'assets/sprites/jabba.jpg');            }            function create() {                game.add.sprite(0, 0, 'jabba');            }            function update() {            }        };    </script></body></html>

If anyone can help, I'll appreciate!

 

Thanks!

Link to comment
Share on other sites

You're telling the game to inject the canvas into a div called 'landmines' but it doesn't exist in the DOM, so you ought to add that after the body tag. Also the code doesn't need to be in a window.onload, but otherwise it looks fine to me. Maybe try pasting in some of the code from an example to see if that works? If it keeps erroring then maybe lib/phaser.js didn't fully download and is corrupted somehow?

Link to comment
Share on other sites

You're telling the game to inject the canvas into a div called 'landmines' but it doesn't exist in the DOM, so you ought to add that after the body tag. Also the code doesn't need to be in a window.onload, but otherwise it looks fine to me. Maybe try pasting in some of the code from an example to see if that works? If it keeps erroring then maybe lib/phaser.js didn't fully download and is corrupted somehow?

 

So, I have downloaded it again and used the files in build folder. Again, it doesn't work. Trying the same code, but with a div:

<!doctype html><html><head>	<meta charset="UTF-8" />	<title>Landmines ~ GrindSoft</title>	<script src="lib/phaser.js"></script></head><body>	<div id="landmines"></div>	<script type="text/javascript">		window.onload = function() {			var game = new Phaser.Game(800, 600, Phaser.AUTO, 'landmines', { preload: preload, create: create, update: update });			function preload() {				game.load.image('jabba', 'assets/sprites/jabba.jpg');			}			function create() {				game.add.sprite(0, 0, 'jabba');			}			function update() {			}		};	</script></body></html>

And occur the same with the examples and tutorial. I have tried with both Apache and nodejuice.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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