Reputation: 153
For the past few days, I have been unable to get phaser to work: just trying to test a hello world program. I've followed the directions on phaser's site exactly, and it still isn't working for me.
I am using node.js.
Here is index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Hello World</title>
<style>
#game_div {
width: 500px;
margin: auto;
margin-top: 50px;
}
</style>
<script type="text/javascript" src="phaser.min.js"></script>
<script type="text/javascript" src="main.js"></script>
</head>
<body>
<div id="game_div"> </div>
</body>
</html>
Here is main.js:
/*jslint node: true */
"use strict";
var game = new Phaser.Game(400, 490, Phaser.AUTO, 'game_div');
var main_state = {
preload: function () {
game.load.image('hello', 'assets/hello.png');
},
create: function () {
this.hello_sprite = game.add.sprite(200, 245, 'hello');
},
update: function () {
this.hello_sprite.angle += 1;
}
}
game.state.add('main', main_state);
game.state.start('main');
The error it gives me is:
'Phaser' was used before it was defined.
var game = new Phaser.Game(400, 490, Phaser.AUTO, 'game_div');
I've really tried looking for solutions to this, but I can't find anything wrong. I'm pretty new to JavaScript and phaser.
Upvotes: 1
Views: 3037
Reputation: 431
in the google chrome shortcut that reads like chrome.exe
try adding --allow-file-access-from-files
then open the browser and load the webpage for linux it will be /usr/bin/google-chrome-stable %U --allow-file-access-from-files
it worked for me the image was loaded even when running locally
Upvotes: 0
Reputation: 3385
The SecurityError above points to the root of the problem: You're opening the file directly in your browser, under which you've no permissions to access local files like this. It needs to be served via a web server. If you need any help with this we cover it in the Getting Started guide on the web site.
Upvotes: 6