简体   繁体   English

Javascript(带有Phaser)错误,显示游戏颜色-括号

[英]Javascript (with Phaser) error showing colour of game -Brackets

I am having problems in JS (and HTML) using Phaser to change a game's background colour. 我在使用Phaser更改游戏背景颜色的JS(和HTML)中遇到问题。 I'm using brackets version 1.3 and using the Live Preview feature to see my code (using Chrome). 我使用的是1.3版括号,并使用实时预览功能来查看我的代码(使用Chrome)。 I have not had this problem before, although I have not used Phaser in brackets since upgrading to Windows 10. Also, I have just noticed that my URL in the preview has changed from being the file destination- eg "C:\\Users\\Daniel\\Desktop\\HTML5 Games(Phaser)\\Simple Jump Game\\index.html" - to a strange IP-style URL (But it is not my IPV4, IPV6 or Default Gateway). 我以前没有这个问题,尽管自从升级到Windows 10以来我没有在括号中使用Phaser。而且,我刚刚注意到预览中的URL已经从文件目标位置更改了,例如“ C:\\ Users \\ Daniel \\ Desktop \\ HTML5 Games(Phaser)\\ Simple Jump Game \\ index.html“-到一个奇怪的IP样式的URL(但这不​​是我的IPV4,IPV6或默认网关)。 It shows - " http://127.0.0.1:55312/index.html ". 它显示-“ http://127.0.0.1:55312/index.html ”。 I am following a textbook (Although making a different game to it- I haven't used Phaser for a while so using it to remind me!) And have copied and pasted from the textbook into my files and I'm still getting an error. 我正在关注一本教科书(尽管与它有着不同的游戏-我已经有一段时间没有使用Phaser了,所以用它来提醒我!)并且已经从教科书中复制并粘贴到了我的文件中,但仍然出现错误。 These are my files: 这些是我的文件:

<!DOCTYPE html>
<html>

  <head>

    <title>Simple Jump game</title>
    <meta charset="utf-8"/>

    <!--Script files-->
    <script type="text/javascript" src="JS/phaser.min.js"></script>
    <script type="text/javascript" src="JS/main.js"></script>

  </head>

  <body>
     <div id="gameDiv"></div>
 </body>
 </html>

And my JS: 而我的JS:

 //The main state of our game
var mainState = { 

    preload: function() { //A function which loads everything (e.g assets),       before the game starts


    },

    create: function() { //A function which physicly adds everything into     our game(e.g sprites)
         game.stage.backgroundColor = '#84B6F7'

         game.physics.startSystem(Phaser.Physics.ARCADE);
    },

    update: function() { //A function which is called 60 times per second and holds all of the game's logic.


    },

};


//Create a new game, using our 'gameDiv' and store it in 'game'
var game = new Phaser.Game(500, 340, Phaser.AUTO, 'gameDiv');


//Add the mainState to our game (as 'main') and start it.
game.add.state('main', mainState);
game.state.start('main');

BTW I included my code not the code from the textbook (Although they should be the same). 顺便说一句,我包括我的代码,而不是教科书中的代码(尽管它们应该相同)。 The textbook is 'Discover Phaser' by Thomas Palef 教科书是托马斯·帕莱夫(Thomas Palef)的“发现相位器”

EDIT: The background colour holds the textbooks colour, the comment next to it has my background colour in. I used the textbook's colour to make sure there isn't an issue with my colour- there isn't. 编辑:背景色保持教科书的颜色,旁边的注释中包含我的背景色。我使用教科书的颜色来确保我的颜色没有问题-没有。

An answer to your other question - 127.0.0.1 means 'localhost' or 'this computer'; 另一个问题的答案-127.0.0.1表示“本地主机”或“此计算机”; most propbably Brackets runs its own server, which, when ran locally, can be accessed at this address. 最有可能的是Brackets运行着自己的服务器,当在本地运行时,可以在该地址访问它。 It may be fine for now to access index.html by its file URL if you're just running some basic set-up code, but once you begin loading assets (images, sounds and so on), your browser will most probably begin throwing cross-origin request errors and you will need to access the game via a local server. 如果您只是运行一些基本的设置代码,现在可以通过其文件URL访问index.html,但是一旦开始加载资源(图像,声音等),浏览器很可能会开始抛出异常跨域请求错误,您将需要通过本地服务器访问游戏。

Fixed! 固定! Silly mistake. 愚蠢的错误。

I did: 我做了:

game.add.state('main', mainState);

instead of: 代替:

game.state.add('main', mainState);

Thanks for everyone's time! 感谢大家的时间!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM