我有一个类的作业,使用javascript创建一个简单的网页。我已经对代码进行了三倍和四倍的检查,它似乎写得很完美;但是,当我去预览时,它只显示我页面的标题。
这是我正在处理的代码。我知道这很简单,但老实说,我无法弄清楚它有什么问题。如果有人能帮助我,我真的很感激。
'use strict';
var game = new Phaser.Game(1024, 600, Phaser.AUTO, 'game', {preload: preload, create: create, update: update, render: render});
var: background;
var: Home1;
var: home2;
var: home3;
var: home5;
var: home6;
var: moose;
var: text;
var: textStyle;
var: textHolder;
function preload() {
game.load.image("background","HomePics/flowerhome.png");
game.load.image("Home1","HomePics/Home1.jpg");
game.load.image("home2","HomePics/home2.jpg");
game.load.image("home3","HomePics/home3.jpg");
game.load.image("home5","HomePics/home5.jpeg");
game.load.image("home6","HomePics/home6.jpg");
game.load.image("moose","HomePics/icon_moose.png");
}
function create() {
background = game.add.sprite(0, 0, "background");
Home1 = game.add.sprite(200, 200, "Home1");
home2 = game.add.sprite(200, 600, "home2");
home3 = game.add.sprite(200, 600, "home3");
home5 = game.add.sprite(400, 600, "home5");
home6 = game.add.sprite(500, 375, "home6");
moose = game.add.sprite(200, 200, "moose");
text = "it's waiting for you"
textSyle = {font: "40px Roboto", fill: "#ff5d5d", align: "center"};
textHolder = game.add.text(0,0, text, textStyle);
}
function update() {
moose.x = game.input.activePointer.x;
moose.y = game.input.activePointer.y;
}
function render() {
}
答案 0 :(得分:2)
如果您不想手动找到语法错误,请使用http://jshint.com/检查语法错误,或者如Lister先生所提到的,请在浏览器的开发者工具中查看控制台。如果开发工具没有显示任何内容,那么由于某种原因,您的代码根本没有被执行。
例如,变量声明没有冒号而写:
var background;
而不是
var: background;
您也可以从这个debugging guide中受益,如果您还没有,请{/ 3}}您的浏览器有。
答案 1 :(得分:0)
请确保您已在浏览器中启用了javascript,否则您编写的任何javascript代码都无法使用!!