简体   繁体   中英

node.js, Get issue

I am using node.js to create a server game. But I have a problem which I don't know how to solve. I will be grateful for any help.

Here is the problem:

在此输入图像描述

index.js:

var express = require('express');
var app = express();
var http = require('http').createServer(app);
var io = require('socket.io').listen(http);

http.listen(8080);
io.set('log level', 1);

app.get('/', function(req, res) {
    console.log("The path to your index.js is " + __dirname);
    res.sendfile(__dirname + '/' + "index.html");
});

index.html:

<html>
</head>
    <title>Server Game</title>
</head>
<body>
    <canvas id = "map" width = "800px" height = "800px"></canvas>

    <script src="scripts/createjs-2013.12.12.min.js"></script>
    <script src="//code.jquery.com/jquery-1.12.0.min.js"></script>

    <script src="/socket.io/socket.io.js"></script>
    <script src="scripts/script.js"></script>
</body>

script.js:

var stage;
var queue;

window.addEventListener('load', init);

function init() {
    stage = new createjs.Stage("map");
    queue= new createjs.LoadQueue(true);
    queue.addEventListener("complete", handleComplete);
    queue.loadManifest([{id:"hud", src:"gui/ui/hud.png"}]);

   createjs.Ticker.addEventListener("tick", tickHandler);
}

function handleComplete(e) {
    var bg = new createjs.Bitmap(queue.getResult("hud"));
    stage.addChild(bg);
}

function tickHandler(e) {
    stage.update();
}

Thanks for attention!

You need to register your public directory with express.static() otherwise your static assets won't be served by your express app.

Add this to your index.js before your routes

app.use(express.static('public'));

Obviously, your static directory doesn't need to be public so just swap that with whatever your static directory is.

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