现在的位置: 首页 > 综合 > 正文

HTML5游戏 BrowserQuest 安装和测试运行

2014年08月11日 ⁄ 综合 ⁄ 共 1891字 ⁄ 字号 评论关闭

前提条件

1、安装 node.js ,下载地址为 http://nodejs.org/

       并通过npm install [MODULE_NAME] 安装如下组件,如npm install underscore

  • underscore
  • log
  • bison
  • websocket
  • websocket-server
  • sanitizer
  • memcache

2、下载BrowserQuest ,地址: https://github.com/mozilla/BrowserQuest

3、 准备一个Webserver,如tomcat7

4、准备一个支持HTML5的浏览器,如FireFox, Chrome等,建议使用FireFox,加上FireBug以便方便对js代码进行跟踪测试

BrowserQuest的目录结构

解压完成的目录结构为

  • bin
  • client
  • server
  • shared
  • tools

目前来说,只和client和server有关系。

其中server需要使用node.js框架启动,client使用tomcat7启动,其实指和用户浏览器相关的部分。

Node启动Server

进入server目录,将 config_local.json-dist 改名为 config_local.json

进入browserquest目录,使用node server/js/main.js命令,如下图所示

Tomcat7启动Client

进入client/config目录,将 config_build.json-dist  改名为 config_build.json ,并且将config_build.json中的 host修改为127.0.0.1

{
    "host": "127.0.0.1",
    "port": 8000
}

修改tomcat的配置,增加一个webcontext,注意docbase是到browserquest目录而不是client目录

<Context docBase="D:/workspaces/HTML5/BrowserQuest-master/" >

</Context>

启动Tomcat

浏览器访问

访问地址为http://localhost:8080/client

即可进入测试。

测试在node的服务端能看到很多输出

[Thu Nov 22 2012 12:29:48 GMT+0800 (中国标准时间)] DEBUG Received: 0,ddd,21,60
[Thu Nov 22 2012 12:29:48 GMT+0800 (中国标准时间)] INFO ddd has joined world1
[Thu Nov 22 2012 12:29:48 GMT+0800 (中国标准时间)] DEBUG Received: 20,927,929,10
20,1021,1022,1120,1121,1122,1220,1221,1222,1320,1321,1322,11920,11921,12120,1212
1,810235,815222,818209
[Thu Nov 22 2012 12:29:48 GMT+0800 (中国标准时间)] DEBUG Pushed 21 new spawns to
 510
[Thu Nov 22 2012 12:29:50 GMT+0800 (中国标准时间)] DEBUG Received: 4,29,225
[Thu Nov 22 2012 12:29:50 GMT+0800 (中国标准时间)] DEBUG ddd is moving to (29, 2
25).
[Thu Nov 22 2012 12:29:50 GMT+0800 (中国标准时间)] DEBUG Received: 26,4
[Thu Nov 22 2012 12:29:54 GMT+0800 (中国标准时间)] DEBUG Received: 21
[Thu Nov 22 2012 12:29:54 GMT+0800 (中国标准时间)] DEBUG group diff:
[Thu Nov 22 2012 12:29:54 GMT+0800 (中国标准时间)] DEBUG Received: 20,926,928,18
20,1821,12220,867220
[Thu Nov 22 2012 12:29:54 GMT+0800 (中国标准时间)] DEBUG Pushed 6 new spawns to
510

无法连接到服务端

最常见的问题是点Play后,页面停留在connecting上,请检查一下两点配置:

1、node.js 服务端是否启动正常,可通过http://127.0.0.1:800/status 如果返回 类似[0,0,0,0] 。如果无法返回检查是否有相关的模块,或8000端口是否被占用。

2、tomcat的web路径要配置到client的上一级,client必须作为子目录。

抱歉!评论已关闭.