一直想學會這個,這兩天還算有空,來弄一下。
跟着中文官網走,主要以 js
開發
下載安裝,
搭建環境網站都有說明
一開始我並沒有安裝
android jdk
之類的東東,只裝了一個Python
,因爲我只打算先弄web
端,後來編譯不出來,於是乾脆全部裝上,於是就成功了。
第一個實例
當然hello world
就不說了,跟着官網走,有一個實例教程
一些基本命令
參照官網
創建項目
cocos new projectname
參數 | 含義 | 可能的值 | 示例 |
---|---|---|---|
l | 語言 | js | cocos new projectname -l js |
運行項目
cocos run -p web
編譯項目
cocos compile -p web -m release
cocos2dx-js
創建一個label
var label = new cc.LabelTTF('Hello World!');
參數:
1. {String} text
2. {String|cc.FontDefinition} fontName Optional, Default: “Arial”
3. {Number} fontSize Optional, Default: 16
4. {cc.Size} dimensions Optional, Default: cc.size(0,0)
5. {Number} hAlignment Optional, Default: cc.TEXT_ALIGNMENT_LEFT
6. {Number} vAlignment Optional, Default: cc.VERTICAL_TEXT_ALIGNMENT_TOP
定時器
schedule(callback, interval, repeat, delay, key)
Schedules a custom selector.
If the selector is already scheduled, then the interval parameter will be updated without scheduling it again.
Parameters:
{function} callback
A function wrapped as a selector
{Number} interval
Tick interval in seconds. 0 means tick every frame. If interval = 0, it’s recommended to use scheduleUpdate() instead.
{Number} repeat
The selector will be executed (repeat + 1) times, you can use kCCRepeatForever for tick infinitely.
{Number} delay
The amount of time that the first tick will wait before execution.
{String} key
The only string identifying the callback
寫了一會發現我懶得再寫了,哈哈,以後再寫好了