简体   繁体   中英

JavaScript code is fine, but webpage preview is only showing my html work

I have an assignment for a class to create a simple web page using javascript. I've triple and quadruple checked the code, and it seems to be written perfectly; however, when I go to preview it, it only shows the heading of my page.

This is the code that I'm working on. I know it's simple, but I honestly can't figure out what's wrong with it. I would really appreciate it if someone would help me out.

'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() {     

}

Use http://jshint.com/ to check for syntax errors when you don't want to find them by hand or, as Mr Lister mentioned, check the console in the developer tools of your browser. If the dev tools display nothing, then for some reason your code is not being executed at all.

For example, variable declarations are written without a colon so:

var background;

instead of

var: background;

You might also benefit from this debugging guide and if you haven't already, please learn to use the developer tools that your browser has.

只要确保您已在浏览器中启用了javascript,否则您编写的任何javascript代码都将无法正常工作!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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