2017年3月28日 星期二

0328 建立專案環境說明 for cocos2d-x 3.15版

第二版說明
因為NDK r13b ,以及android sdk build tools 更新問題。
導致cocos compile 指令 在進行打包APK的時候,
會卡在最後的freetype2 沒有對應的.a檔
所以需重新安裝對應的cocos2d-x 版本以及執行下載第三方LIB動作

步驟一:安裝cocos2d-x (須按裝 python2.75 版)
  用git 下載 https://github.com/cocos2d/cocos2d-x.git
 然後執行 cd cocos2d-x
  python download-deps.py
  git submodule update --init
  python setup.py
執行完畢後 要確認所有變數都已經有設定了
例如是否有指定NDK目錄之類

額外說明:
產生cocos2d lib (記得要重新啟動CMD)
執行
cocos gen-libs -p win32 --vs 2013 -m release
或是
cocos gen-libs -p win32 --vs 2013 -m debug
將 D:\Task\cocos2d-x\prebuilt 複製到 專案下的 Lib_cocos2d
如名稱不同,記得改名
libbox2d_2013.lib =>libbox2d.lib
libSpine_2013.lib =>libSpine.lib

步驟二
下載  Lib_libpomelo2 (https://github.com/NetEase/libpomelo2)
    解壓縮到cocos2d-x 目錄下 本範例是解壓縮到 D:\Task\cocos2d-x\libpomelo2

額外說明:
產生 pomelo Lib
用VS2013 開啟專案  D:\Task\cocos2d-x\libpomelo2\libpomelo2.vcxproj
並且加入現有專案 D:\Task\cocos2d-x\libpomelo2\deps\uv\libuv.vcxproj
D:\Task\cocos2d-x\libpomelo2\deps\openssl\openssl.vcxproj
編譯程式。取得LIB,複製lib (預設是在D:\Task\cocos2d-x\libpomelo2\Default\lib)
到專案下的Lib_libpomelo2

步驟三:程式下載
  git路徑:ssh://git@192.168.1.250:software/Slotgame_APP.git

  A.PC版的編譯(需先安裝VS2013):  
下載後 進入proj.win32 目錄 執行 SlotGame_cocos2dx.sln (需用VS 2013 以上的版本)
(如果無法載入專案,請確認 SlotGame_cocos2dx.vcxproj 檔案中
    屬性 cocos2dx.props 跟 cocos2d_headers.props
是否有正確指向 cocos2d-x 安裝路徑)
F5 開始執行

  B.android 版編譯(需先安裝Android-studio android-ndk-r13b(x86_64版本)  jdk-8u101-windows-x64.exe):
執行CMD , 可先測試cocos -v 確認是否有安裝正確
android-ndk-r13b 預設解壓縮在D:/android-ndk-r13b
(驗證是否有成功安裝 可以執行 cocos new HelloWorld -l cpp,看建立起來的專案是否可以 VS 編譯)

執行CMD,進入proj.Android-studio,
指令簡易說明 //-q  簡化輸出 -p指定平台 -m release -ap 指定ANDROID版本
範例指令:
cocos compile -q -p android --android-studio  -m release --ap android-16  // (android4.1 出貨版)
cocos compile -q -p android --android-studio  --ap android-16 --app-abi armeabi // (android4.1 debug版 for NDKr13b)
cocos compile -p android --android-studio  --ap android-16  // (android4.1)
cocos compile -p android --android-studio  --ap android-21  // (android5.0)
cocos compile -p android --android-studio  --ap android-19  // (android4.4)
cocos compile -p android --android-studio  --ap android-23  // (android6.0)
編譯程式,出現編譯成功後
可以透過 android-studio 開啟,透過ADB 傳送到手機。
或是直接丟到手機安裝。

如果要執行 android-19 之前的版本需將  #include <stdlib.h> 加入至
cocos2d-x\libpomelo2\include\pomelo.h
cocos2d-x\cocos\platform\CCCommon.h

Q:當出現 ndk_module_path 路徑有問題時
A:可以到 proj.Android-studio下的檔案 build-cfg.json 進行修改。

Q:當出現 cocos2d-x 編譯路徑指向其他路徑
A:修改 proj.Android-studio下的檔案 settings.gradle 進行修改。

Q:當在andtod-studio 出現 couldn't find "libMyGame.so"
A:修改 proj.android-studio\app\AndroidManifest.xml

Q:出現 format not a string literal and no format arguments [-Werror=format-security]
A:修改 proj.android-studio\app\jni\Application.mk
  增加 APP_CFLAGS += -Wno-error=format-security


cocos2dx-lua 建立滑鼠監聽

重要關鍵字  EVENT_MOUSE_SCROLL addEventListenerWithSceneGraphPriority      if IsPc() then --建立滑鼠監聽         local listener = cc.EventListenerMouse...