Sunday, August 9, 2015

android studio ndk with java 8

You had errors compiling the samples until I append
tasks.withType(JavaCompile) {
    sourceCompatibility = JavaVersion.VERSION_1_7
    targetCompatibility = JavaVersion.VERSION_1_7
}

to build.gradle (app).

ctags for cocos2d-x

find . -name "*.h" -o -name "*.c" -o -name "*.cpp" -o -name "*.m" -o -name "*.mm" -o -name "*.java" -o -name "*.py" -o -name "*.lua" > src.files

ctags -R --c++-kinds=+px --fields=+iaS --extra=+q -L src.files

Wednesday, July 29, 2015

cocos2dx, get label from layer

I could keep label reference in a member variable, but I preferred to manage it in the layer structure. So far I found the only api to get children is layer->getChildByXxx.  They all return Node*. I get Label is descendant of Node as it can be added as a child of layer. So I did this.

label->setName("label");
// add the label as a child to this layer

this->addChild(label, 1);

and 

auto label = dynamic_cast<Label*>(this->getChildByName("label"));

It works so far. Correct me if there is a better way.

Sunday, July 26, 2015

cocos2dx + opencv static linking

I spent much time to get it work.

There is a Japanese blog showing how to setup cocos2dx with opencv, but there is one missing part.
http://blog.szmake.net/archives/845

It works for OPENCV_LIB_TYPE:=SHARED. It is also the default option of opencv for android. But it fails on OPENCV_LIB_TYPE:=STATIC and there will be linking errors.

The reason is that cocos2dx uses static linking by default and overrides opencv's libs. So you need to update LOCAL_STATIC_LIBRARIES := cocos2dx_static to LOCAL_STATIC_LIBRARIES += cocos2dx_static. Now the project compiles.

Again, you need 

OpenCV_INSTALL_MODULES:=on
OPENCV_CAMERA_MODULES:=off
OPENCV_LIB_TYPE:=STATIC

include /path/to/OpenCV.mk

LOCAL_C_INCLUDES+= /path/to/OpenCV/include

LOCAL_STATIC_LIBRARIES += cocos2dx_static

Friday, July 24, 2015

blender to cocos2dx

In the doc of cocos2dx, it is mentioned that you can use blender to export fbx and convert it into c3t/c3b for sprite3D. But it does not say how. I googled around and found a few posts helpful.

http://a2dr.blogspot.com/2015/05/cocos2d-x-converting-fbx-to-c3b.html

I exported my crate, but have not tested animation yet.

Here are the steps
1. Edit your object in blender.
2. Export the selected object to fbx. Check "selected objects" and leave other options default. Some says you need select FBX 6.1 ASCII, but default FBX 7.4 binary works for me.
3. Convert fbx to c3b/c3t with the binary fbx-conv in cocos2dx tools folder.
4. Add c3b/c3t and texture to project Resources folder. This step is critical, the converted fbx or c3b/c3t do not contain texture in them. Some says you need a sub folder named Tex to hold textures, but I just put them under root of Resource.
5. Create your Sprite3D with the converted c3b files.




Tuesday, July 21, 2015

cocos2d-x + eclipse

Although android studio 1.3 rc claims support ndk natively, cocos2d-x does not support it yet. Or I did not find the right doc. I decided to fall back to eclipse+adt.

The official doc is not completed here
http://www.cocos2d-x.org/wiki/Android_with_Eclipse_Installation_and_Setup

After doing so, I got errors in eclipse. I googled, and found out I need to add libcocos2dx from "cocos2d/cocos/platform/android/java" to get rid those errors.  Go to project properties->builders, and check CDT builder.

Leave everything else default.

I do not know how to change target SDK level, e.g. to 22(lollipop) or abi. But I can do that with cmd, e.g., "cocos compile -p android -ap android-22 --app-abi armeabi-v7a".

Thursday, July 9, 2015

build opencv (3.0.0) for android form source

# Set up your NDK path. You also need java 6+, ant 1.8+, and python 2.7 according to opencv doc.
unzip ~/Downloads/opencv-3.0.0.zip
cd opencv-3.0.0/platforms
mkdir build_android_arm
cd build_android_arm
cmake -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON -DCMAKE_TOOLCHAIN_FILE=../android/android.toolchain.cmake $@ ../..
# If you prefer clang to gcc
# cmake -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON -DCMAKE_TOOLCHAIN_FILE=../android/android.toolchain.cmake -DANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-clang3.6 $@ ../..
make -j 8

make install
# Till now, opencv is build, you will get a bunch of static libs by default. Everything is under build_android_arm/install