I am a relatively new JS developer if you can even call me one yet, and I am trying to learn the Phaser framework. Anyway, I have what most would call the 'Basic Phaser setup' but when I run my program in the browser (Chrome) the console throws an error saying, Uncaught ReferenceError: Phaser is not defined
on line 1 which is where I created my Phaser 'game' instance. This prevents my main code from running which is making a background tileSprite from scrolling up by 2 pixels every frame I was watching a tutorial video and I tried to mimic the video maker's code exactly but my code still won't run. I would be extremely grateful if anyone could help me out and tell me what is going wrong. Thank you!
Here is my HTML:
<!DOCTYPE html>
<html>
<head>
<title>Js Scroller</title
<script type="text/javascript" src='phaser.min.js'></script>
<script type="text/javascript" src='scrolling.js'></script>
</head>
<body>
<style>
</style>
</body>
</html>
I am a relatively new JS developer if you can even call me one yet, and I am trying to learn the Phaser framework. Anyway, I have what most would call the 'Basic Phaser setup' but when I run my program in the browser (Chrome) the console throws an error saying, Uncaught ReferenceError: Phaser is not defined
on line 1 which is where I created my Phaser 'game' instance. This prevents my main code from running which is making a background tileSprite from scrolling up by 2 pixels every frame I was watching a tutorial video and I tried to mimic the video maker's code exactly but my code still won't run. I would be extremely grateful if anyone could help me out and tell me what is going wrong. Thank you!
Here is my HTML:
<!DOCTYPE html>
<html>
<head>
<title>Js Scroller</title
<script type="text/javascript" src='phaser.min.js'></script>
<script type="text/javascript" src='scrolling.js'></script>
</head>
<body>
<style>
</style>
</body>
</html>
Here is my JavaScript:
var game = new Phaser.Game(800,600,Phaser.CANVAS,'gameDiv');
var starfield;
var mainState = {
preload: function() {
game.load.image('starfield', '/Users/wyatthume/Desktop/starfield.png');
},
create: function() {
starfield = game.add.tileSprite(0,0,800,600, 'starfield');
},
update: function() {
starfield.tilePosition.y += 2;
}
}
game.state.add('mainState', mainState);
game.state.start(mainState);
Share
Improve this question
edited Dec 19, 2017 at 6:58
Tiago Cogumbreiro
5492 silver badges13 bronze badges
asked Dec 19, 2017 at 1:30
ninman8ninman8
111 silver badge3 bronze badges
4
- The dev tools provide a Network tab. Regarding the Phaser script source, please confirm: Is the resource found (e.g. HTTP 200 response)? If not, which actual URL is requested? – Sebastian Simon Commented Dec 19, 2017 at 1:38
-
Also, you have an unclosed tag at
</title
. – Sebastian Simon Commented Dec 19, 2017 at 1:43 - Im sorry, but i'm not really sure were this would show up in the network tab – ninman8 Commented Dec 20, 2017 at 0:02
- Are you using a variation of Phaser 2 or Phaser 3? – camjocotem Commented May 3, 2018 at 16:05
2 Answers
Reset to default 2Be certain that the path to Phaser can be resolved based on where your index.html.
In this case, if your index.html is in /home/foo/Web/index.html, then make sure the file /home/foo/Web/phaser.min.js exists.
This is a very old thread but as it es up on Google on the very first page and it is unanswered, I'll answer it. :)
Phaser is not defined because the asker has opened the HTML file directly and such, the phaser path was incorrectly read. Whenever you use a webserver, make sure you call it correctly.
Your browser should display
http://localhost/phaser3-tutorial-src/part3.html
(or something along this line)
but
- NEVER C:/ D:/ E:/
I hope this will help someone out there! Happy phasering.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745238402a4618027.html
评论列表(0条)