cocos2d-x console @cocos talks #3
TRANSCRIPT
Cocos2d-x Console
Akihiro Matsuura @ Syuhari, Inc.
About me• 松浦 晃洋• 株式会社シュハリ 代表取締役• Cocos2d-x ゲーム開発
• 書籍、雑誌などの執筆• Cocos2d-x エヴァンジェリスト
開発のプロが教えるCocos2d-x逆引きガイドブック
Cocos2d-x GameDevelopment Essentials
Building Android Games with Cocos2d-x
海外での出版に協力
Cocos2d-x 開発者の祭典!4/2 北京
http://devcon.cocos.com/
週刊アスキー でレポート
http://weekly.ascii.jp/elem/000/000/325/325033/
Agenda
• Cocos v2.2 • Console 機能
Cocos v2.2
• メリット
• プロジェクトの新規作成が簡単
• Cocos2d-x がプレビルドされている
• Build が早い!
• デメリット
• Cocos2d-x のソースがヘッダしか見れない
• カスタマイズできない
Cocos framework v3.5
Console 機能を利用する
What about Console
• アプリケーションの情報を見られる
• シーングラフ
• テクスチャキャッシュ
• Xcode や DDMS なしで端末のログを見られる
• タッチ操作をシミュレートできる
• コマンドを追加することができる
Start Console
// Console クラスのインスタンスを取得 auto console = Director::getInstance()->getConsole(); // TCPポートを指定して接続を待ち受ける console->listenOnTCP(6010);
Connect your game
$ telnet localhost 6010 Trying ::1... telnet: connect to address ::1: Connection refused Trying 127.0.0.1... Connected to localhost. Escape character is '^]'.
help command> help
Available commands: allocator Display allocator diagnostics for all allocators config Print the Configuration object debugmsg Whether or not to forward the debug messages on the console. Args: [on | off] director director commands, type -h or [director help] to list supported directives exit Close connection to the console fileutils Flush or print the FileUtils info. Args: [flush | ] fps Turn on / off the FPS. Args: [on | off] help Print this message projection Change or print the current projection. Args: [2d | 3d] resolution Change or print the window resolution. Args: [width height resolution_policy | ] scenegraph Print the scene graph texture Flush or print the TextureCache info. Args: [flush | ] touch simulate touch event via console, type -h or [touch help] to list supported directives upload upload file. Args: [filename base64_encoded_data] version print version string >
scenegraph command> scenegraph > <Scene | tag = -1> - <Node | Tag = -1 - <Layer | Tag = -1> -- <Node | Tag = 0 --- <Sprite | Tag = 5, TextureID = 4> Total Nodes: 5
texture command
> texture > “/HelloWorld.png" rc=2 id=4 960 x 640 @ 32 bpp => 2400 KB "/cc_2x2_white_image" rc=1 id=3 2 x 2 @ 32 bpp => 0 KB "/cc_fps_images" rc=4 id=2 999 x 54 @ 16 bpp => 105 KB TextureCache dumpDebugInfo: 3 textures, for 2505 KB (2.45 MB)
Upload a file> upload filename base64
• 指定したファイル名で FileUtiles::getWritablePath のパスへフィルをアップロード
• ファイルの内容は base64 でエンコードして指定
Upload a file by script#!/bin/sh
if [ $# -lt 2 ]; then echo "IPアドレスとアップロードするファイルを指定してください" echo "usage : ./upload.sh ipaddress filename" exit 1 fi
path=$2 filename=${path##*/}
file=`cat $2 | base64`
commandline() { sleep 1; echo "upload $filename $file" sleep 5; }
commandline | telnet $1 6010
Custom Command
Dispatch Eventcocos2d::Console::Command event = { "event", "dispatch custom event. Args:[event name]", [](int fd, const std::string& args) {
Director::getInstance()-> getEventDispatcher()->dispatchCustomEvent(args);
const char msg[] = "dispatched custom event!\n"; send(fd, msg, sizeof(msg),0);
}}; Director::getInstance()->getConsole()->addCommand(event);
Remove a filecocos2d::Console::Command del = { "remove", "remove a file. Args:[filename]", [](int fd, const std::string& args) {
auto path = FileUtils::getInstance()-> getWritablePath() + args;
int ret = remove(path.c_str()); if (ret==0) { const char msg[] = "removed file!\n"; send(fd, msg, sizeof(msg),0); } else { const char msg[] = "could not remove file\n"; send(fd, msg, sizeof(msg),0); }
}}; Director::getInstance()->getConsole()->addCommand(del);
注意点
Scheduler *sched = Director::getInstance()->getScheduler(); sched->performFunctionInCocosThread( [](){
// メインスレッドで行う処理 });
• コマンドはネットワークスレッドで実行される
• UI などの操作をするときは注意が必要
• メインスレッドで実行したい処理は下記のように処理する
Demo
Summary• Cocos v2.2 はぜひ試してみて!
• Console は便利!カスタマイズできるのがイイ!
Cocos2d-x で開発したいエンジニア
大募集中!• @syuhari
• facebook.com/syuhari