Todi Posted January 22, 2014 Share Posted January 22, 2014 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 More sharing options...
rich Posted January 22, 2014 Share Posted January 22, 2014 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 More sharing options...
Todi Posted January 22, 2014 Author Share Posted January 22, 2014 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 More sharing options...
rich Posted January 22, 2014 Share Posted January 22, 2014 Hang on, which version did you download? master or dev branch? (if dev, that is why it's crashing.. grab from master). Link to comment Share on other sites More sharing options...
Todi Posted January 22, 2014 Author Share Posted January 22, 2014 Hang on, which version did you download? master or dev branch? (if dev, that is why it's crashing.. grab from master). Master! v1.1.3 EDIT: Just a simple restart and voilá! It works! Thanks Rich! The Jabba! LOL! Link to comment Share on other sites More sharing options...
rich Posted January 22, 2014 Share Posted January 22, 2014 Hah! The classic "have you rebooted?" Todi 1 Link to comment Share on other sites More sharing options...
Todi Posted January 22, 2014 Author Share Posted January 22, 2014 Hah! The classic "have you rebooted?" But it is really strange. Using nodejuice it did not work, the same error occur, but I changed to the SimpleHTTPServer.py and it works like I have it running on Apache. Weird, huh?! Link to comment Share on other sites More sharing options...
Recommended Posts