本文介紹如何在Windows平台下載下傳LimeJS。LimeJS的官網位址為 http://www.limejs.com/,可以在此下載下傳到LimeJS的壓縮包。将其解壓後,進入bin子目錄,裡面有個lime.py檔案,這是一個Python腳本,毫無疑問要安裝一個Python解釋器了。我下載下傳并安裝的Python版本是3.2。
然後打開一個CMD指令提示符,改變目前目錄至LimeJS的bin子目錄下,運作lime.py init指令,輸出為Lime requires git. Get it from http://git-scm.com/download。git是一個分布式的版本控制系統,lime需要用它下載下傳Closure Library、Box2D、Closure compiler和Closure Templates。既然是在windows平台,下個windows版的git安裝程式就是了。
将git安裝好以後,需要能夠在CMD指令提示符下運作它,方法是将git.exe所在的目錄添加至環境變量PATH中(git.exe一般在C:\Program Files\Git\bin目錄下)。配置好git後,再次運作lime.py init,所有的軟體包都已正确下載下傳,但在更新的時候卻出現了如下錯誤:
Updating Closure deps file
digitalfruit-limejs-e5e49e0\closure\closure/goog/deps.js"
Traceback (most recent call last):
File "digitalfruit-limejs-e5e49e0\closure\closure\bin\build\depswriter.py", line 206, in <module> main()
File "digitalfruit-limejs-e5e49e0\closure\closure\bin\build\depswriter.py", line 182, in main
path_to_source.update(_GetRelativePathToSourceDict(root, prefix=prefix))
File "digitalfruit-limejs-e5e49e0\closure\closure\bin\build\depswriter.py", line 149, in _GetRelativePathToSourceDict
path_to_source[prefixed_path] = source.Source(source.GetFileContents(path))
File "digitalfruit-limejs-e5e49e0\closure\closure\bin\build\source.py", line 98, in GetFileContents
return fileobj.read()
UnicodeDecodeError: 'gbk' codec can't decode bytes in position 8291-8292: illegal multibyte sequence
對于這個錯誤,網上已經有人給出了解決辦法。具體地,首先定位到limeJS\closure\closure\bin\build目錄,裡面有兩個檔案:source.py和depswriter.py。在source.py中找到fileobj = open(path)這一行(接近檔案末尾處),将其替換為fileobj = open(path, encoding=’utf-8’)。然後在depswriter.py中找到paths = source_map.keys()這一行(一般在51行),将其替換為paths = list(source_map.keys())。
經過上面的修改, lime.py init就可以正常運作了。
附:
1. Closure Tools
Closure工具包括:
JavaScript優化器:移除不需要的代碼,壓縮其餘的代碼以實作速度最大化;
與Firebug協同工作的Firefox擴充Closure Inspector,目的是簡化調試;
Closure compiler:能以指令行、Web應用或Firefox擴充形式運作;
Closure Library:Google的标準JavaScript類庫;
Closure Templates:提供了一組預編譯的JavaScript接口元件。
2. Box2D
一個很有名的2D實體遊戲引擎。