[英]node.js, Get issue
我正在使用node.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");
});
<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>
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();
}
感謝您的關注!
您需要使用express.static()
注冊您的public
目錄,否則Express應用程序將不會提供您的靜態資產。
在路線之前將其添加到index.js
app.use(express.static('public'));
顯然,您的靜態目錄不需要public
因此只需將其與您的靜態目錄交換即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.