先日(2017年6月30日の日記参照)の続きです。Cocos2d-xがビルドできたら、開発環境のセットアップをします。といってもsetup.pyを実行して、質問に答えるだけです。
$ cd cocos2d-x $ ./setup.py Setting up cocos2d-x... ->Check environment variable COCOS_CONSOLE_ROOT ->Search for environment variable COCOS_CONSOLE_ROOT... ->COCOS_CONSOLE_ROOT not found -> Add COCOS_CONSOLE_ROOT environment variable... ->Added COCOS_CONSOLE_ROOT=/home/katsuhiro/usr/src/cocos2d-x/tools/cocos2d-console/bin ... ->Check environment variable NDK_ROOT ->Search for environment variable NDK_ROOT... ->NDK_ROOT not found ->Search for command ndk-build in system... ->Command ndk-build not found ->Please enter the path of NDK_ROOT (or press Enter to skip): ★★Enterを押す★★ ... ->Check environment variable ANDROID_SDK_ROOT ->Search for environment variable ANDROID_SDK_ROOT... ->ANDROID_SDK_ROOT not found ->Search for command android in system... ->Command android not found ->Please enter the path of ANDROID_SDK_ROOT (or press Enter to skip): ★★Enterを押す★★ ... Please execute command: "source /home/katsuhiro/.bashrc" to make added system variables take effect
最初にAndroid NDKの場所を聞かれ、次にAndroid SDKの場所を聞かれます。もしAndroid向けにビルドしないのであれば、Enterを連打して無視しても構いません。私はスマホでもゲームを動かしてみたかったのでインストールしました。
Android SDKのコマンドラインツールは Android Studioのダウンロードサイトの一番下にある "Get just the command line tools" にあります。Android NDKは Android NDKのダウンロードサイトにあります。
SDKとNDKはどこに配置しても良いみたいです。私は~/usr/lib/ の下に放り込んでおきました。
$ cd ~/usr/lib $ unzip android-ndk-r15b-linux-x86_64.zip ...省略... $ ln -s android-ndk-r15b android-ndk $ cd ~/usr/lib $ mkdir android-sdk $ cd android-sdk $ unzip sdk-tools-linux-3859397.zip ...省略... $ cd ~/usr/lib $ tree -L 2 . ├──android-ndk -> android-ndk-r15b ├──android-ndk-r15b │ ├──CHANGELOG.md │ ├──README.md │ ├──build │ ├──meta │ ├──ndk-build │ ├──ndk-depends │ ├──ndk-gdb │ ├──ndk-stack │ ├──ndk-which │ ├──platforms │ ├──prebuilt │ ├──python-packages │ ├──shader-tools │ ├──simpleperf │ ├──source.properties │ ├──sources └──android-sdk └──tools
それとSDKやNDKのバージョン名が変わるたびにセットアップし直すのは面倒だったので、NDKはシンボリックリンクを張りました。手抜きです……。
$ cd cocos2d-x $ ./setup.py Setting up cocos2d-x... ->Check environment variable COCOS_CONSOLE_ROOT ->Search for environment variable COCOS_CONSOLE_ROOT... ->COCOS_CONSOLE_ROOT is found : /home/katsuhiro/usr/src/cocos2d-x/tools/cocos2d-console/bin ... ->Check environment variable NDK_ROOT ->Search for environment variable NDK_ROOT... ->NDK_ROOT not found ->Search for command ndk-build in system... ->Command ndk-build not found ->Please enter the path of NDK_ROOT (or press Enter to skip): /home/katsuhiro/usr/lib/android-ndk -> Add NDK_ROOT environment variable... ->Added NDK_ROOT=/home/katsuhiro/usr/lib/android-ndk ->Check environment variable ANDROID_SDK_ROOT ->Search for environment variable ANDROID_SDK_ROOT... ->ANDROID_SDK_ROOT not found ->Search for command android in system... ->Command android not found ->Please enter the path of ANDROID_SDK_ROOT (or press Enter to skip): /home/katsuhiro/usr/lib/android-sdk -> Add ANDROID_SDK_ROOT environment variable... ->Added ANDROID_SDK_ROOT=/home/katsuhiro/usr/lib/android-sdk ... Please execute command: "source /home/katsuhiro/.bashrc" to make added system variables take effect
環境設定はうまく行ったようです。最後に出ているメッセージの言う通りsource ~/.bashrcを実行すれば、cocosというコマンドが実行できるようになっているはずです。
Cocos2d-xの開発ではcocosコマンドを使うそうです。まずはcocos newでゲームのプロジェクト(テンプレート?)を生成します。
プロジェクト名はmygame1で、パッケージ名はnet.katsuster.mygame1(-p net.katsuster.mygame1)、C++ で開発します(-l cpp)。プロジェクトをディレクトリmygameに置いてもらいます(-d mygame)。何も指定しないとMyCppGameというディレクトリ名になりますが、リネームしても別に問題はありません。
$ mkdir ~/cocos $ cd ~/cocos $ cocos new mygame1 -p net.katsuster.mygame1 -l cpp -d mygame > Copy template into /home/katsuhiro/cocos/mygame/mygame1 > Copying Cocos2d-x files... > Rename project name from 'HelloCpp' to 'mygame1' > Replace the project name from 'HelloCpp' to 'mygame1' > Replace the project package name from 'org.cocos2dx.hellocpp' to 'net.katsuster.mygame1' > Replace the Mac bundle id from 'org.cocos2dx.hellocpp' to 'net.katsuster.mygame1' > Replace the iOS bundle id from 'org.cocos2dx.hellocpp' to 'net.katsuster.mygame1' $ ls mygame mygame1 $ ls mygame/mygame1/ CMakeLists.txt cocos2d proj.ios_mac proj.win10 Classes proj.android proj.linux proj.win32 Resources proj.android-studio proj.tizen
ディレクトリを覗くと、訳のわからないファイルが大量に生成されていて面食らいますが、とりあえず何も気にせず、ビルド&実行してみます。
ビルド対象は先程生成したmygame1(-s mygame/mygame1)で、ターゲットはLinux向け(-p linux)です。初回のビルドはかなり時間がかかりますが、二回目以降は変更した部分だけビルドするため、非常に早いです。
$ cocos compile -s mygame/mygame1/ -p linux Building mode: debug running: 'cmake -DCMAKE_BUILD_TYPE=Debug -DDEBUG_MODE=ON ..' -- The C compiler identification is GNU 6.3.0 ...(初回だけかなり時間掛かります)... [100%] Building CXX object CMakeFiles/MyGame.dir/Classes/HelloWorldScene.cpp.o [100%] Building CXX object CMakeFiles/MyGame.dir/Classes/AppDelegate.cpp.o [100%] Linking CXX executable bin/MyGame [100%] Built target MyGame Build succeed. $ cocos run -s mygame/mygame1/ -p linux Building mode: debug running: 'cmake -DCMAKE_BUILD_TYPE=Debug -DDEBUG_MODE=ON ..' ... [100%] Built target MyGame Build succeed. Deploying mode: debug Starting application. running: '/home/katsuhiro/cocos/mygame/mygame1/bin/debug/linux/MyGame' /home/katsuhiro/cocos/mygame/mygame1/bin/debug/linux/MyGame: error while loading shared libraries: libfmod.so.6: cannot open shared object file: No such file or directory Error running command, return code: 127.
上記ではビルドだけするため、あえてcocos compileを使いましたが、実はcocos runがビルドと実行を同時にやってくれるので、cocos compileは使う必要がありません。
それは良いとしてcocos runが失敗してしまいました。libfmod.so.6が無いとか言っています。このライブラリはcocos2d-x/external/linux-specific/fmod/prebuilt/64-bit/libfmod.soに置いてあるようなのですが、名前がちょっと違っているので、libfmod.so.6という名前のシンボリックリンクを作ってあげて、ライブラリのパスも通してあげると動きます。
$ cd ~/usr/src/cocos2d-x $ cd external/linux-specific/fmod/prebuilt/64-bit $ ln -s libfmod.so libfmod.so.6 $ echo 'export LD_LIBRARY_PATH=$COCOS_X_ROOT/cocos2d-x/external/linux-specific/fmod/prebuilt/64-bit' >> ~/.bashrc $ source ~/.bashrc $ cd ~/cocos $ cocos run -s mygame/mygame1/ -p linux ... Build succeed. Deploying mode: debug Starting application. running: '/home/katsuhiro/cocos/mygame/mygame1/bin/debug/linux/MyGame' Ready for GLSL Ready for OpenGL 2.0 gl.supports_OES_packed_depth_stencil: false gl.supports_OES_depth24: false gl.supports_OES_map_buffer: false gl.supports_vertex_array_object: true gl.renderer: Gallium 0.4 on llvmpipe (LLVM 3.9, 128 bits) gl.version: 3.0 Mesa 13.0.6 cocos2d.x.compiled_with_gl_state_cache: true cocos2d.x.version: cocos2d-x-3.15.1 gl.supports_S3TC: true cocos2d.x.build_type: DEBUG cocos2d.x.compiled_with_profiler: false gl.vendor: VMware, Inc. gl.max_texture_units: 96 gl.max_texture_size: 8192 gl.supports_ATITC: false gl.supports_ETC1: false gl.supports_PVRTC: false gl.supports_NPOT: true gl.supports_BGRA8888: false gl.supports_discard_framebuffer: false libpng warning: iCCP: known incorrect sRGB profile cocos2d: QuadCommand: resizing index size from [-1] to [2560]
下記のように宇宙人のような顔が描いてある画面が出れば成功です。
そういえば何も考えずTigerVNC上で実行していますが、難無く60fps出て驚きました。画面サイズが小さくて、動きがほとんど無いから軽いだけかも知れませんけど、便利だし問題起きるまでVNC越しで開発してみようかなあ。
ひとまずLinux向けには作り始めることができそうです。今回はここまで。
< | 2017 | > | ||||
<< | < | 07 | > | >> | ||
日 | 月 | 火 | 水 | 木 | 金 | 土 |
- | - | - | - | - | - | 1 |
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 | - | - | - | - | - |
合計:
本日:
管理者: Katsuhiro Suzuki(katsuhiro( a t )katsuster.net)
This is Simple Diary 1.0
Copyright(C) Katsuhiro Suzuki 2006-2023.
Powered by PHP 8.2.15.
using GD bundled (2.1.0 compatible)(png support.)