Table of Contents generated with DocToc
- cocos2d-x: v3.14+
- Cocos Creator: v1.4+
Given that Creator uses a component based model to create its objects, and cocos2d-x has its monolithic structure, it is only possible to support a limited subset of Creator features.
Supported nodes:
Scene
Sprite
Canvas
(but only one per scene)ScrollView
Label
EditBox
ParticleSystem
TiledMap
Button
ProgressBar
RichText
: need cocos2d-x 3.16+ to support img tag, refer to this issue for detail informationSpineSkeleton
Widget
: only supportsAlignOnce
Animations
: only supports linear animationVideoPlayer
: iOS should addMediaPlayer.framework
to the projectWebView
Slider
Toggle
ToggleGroup
PageView
Mask
Collider
Prefab
DragonBones
Supporting JavaScript scripts would be overkill. If you need JavaScript scripting support, just use Creator.
Can fetch this branch and run cpp-empty-test
or lua-empty-test
. The branch based on v3.15, don't forget to update external libraries.
dragonbones is not supported for lua currently, will add dragonbones quickly.
Currently support on Mac, iOS and Android, will support more platforms quickly. Can just modify project file to add cpp files in reader
to support other platforms.
- download and install Cocos Creator
- use Cocos Creator to open creator_project
- click Project -> LuaCPP Support -> Setup Target Project
- fill in Project Path, it is a c++ or lua project created by cocos2d-x(3.14+) console
- click Build
You will find:
- all needed source codes are generated into
NATIVE_PROJECT_ROOT/Classes/reader(it is NATIVE_PROJECT_ROOT/frameworks/runtime-src/Classes/reader for lua project)
- all needed resources are generated into
NATIVE_PROJECT_ROOT/Resources/creator(it is NATIVE_PROJECT_ROOT/frameworks/runtime-src/Resources/creator for lua project)
Should add reader
into header search path. If developing for Android, can just use existing Android.mk
, for example, use the Android.mk
into your game's Android.mk
like this:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := MyGame_shared
LOCAL_MODULE_FILENAME := libMyGame
LOCAL_SRC_FILES := hellocpp/main.cpp \
../../Classes/AppDelegate.cpp \
../../Classes/HelloWorldScene.cpp
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes
# _COCOS_HEADER_ANDROID_BEGIN
# _COCOS_HEADER_ANDROID_END
LOCAL_STATIC_LIBRARIES := cocos2dx_static
# LOCAL_STATIC_LIBRARIES += creator_reader_lua # for lua project
LOCAL_STATIC_LIBRARIES += creator_reader # add dependence
# _COCOS_LIB_ANDROID_BEGIN
# _COCOS_LIB_ANDROID_END
include $(BUILD_SHARED_LIBRARY)
$(call import-module,.)
$(call import-module, ./../../Classes/reader) # import module path
If developing with Lua, then need to add CreatorReaderBinding.cpp
into plugin's Android.mk.
// mygame.cpp
#include "reader/CreatorReader.h"
void some_function()
{
creator::CreatorReader* reader = creator::CreatorReader::createWithFilename("creator/CreatorSprites.ccreator");
// will create the needed spritesheets + design resolution
reader->setup();
// get the scene graph
Scene* scene = reader->getSceneGraph();
// ...and use it
Director::getInstance()->replaceScene(scene);
}
Register creator binding codes in c++
#include "reader/lua-bindings/creator_reader_bindings.hpp"
...
register_creator_reader_manual(L);
Use in lua
local creatorReader = cc.CreatorReader:createWithFilename('creator/CreatorSprites.ccreator')
creatorReader:setup()
local scene = creatorReader:getSceneGraph()
cc.Director:getInstance():replaceScene(scene)
ColliderManager
is used to manage collisions. Every scene has an instance of ColliderManager
. You can use it like this to listen collision events:
creator::CreatorReader* reader = creator::CreatorReader::createWithFilename("creator/CreatorSprites.ccreator");
// will create the needed spritesheets + design resolution
reader->setup();
// get the scene graph
Scene* scene = reader->getSceneGraph();
auto colliderManager = scene->getColliderManager();
colliderManager->registerCollitionCallback([=](creator::Contract::CollisionType type,
creator::Collider* collider1,
creator::Collider* collider2) {
if (type == creator::Contract::CollisionType::ENTER)
colliderManager->enableDebugDraw(true);
if (type == creator::Contract::CollisionType::EXIT)
colliderManager->enableDebugDraw(false);
}, "");
More features of colliderManager
can refer to the header file.
Currently, the plugin is not completed enough, so we don't put it into Cocos Creator plugin store. But you can copy creator_project/packages/creator_luacpp_support
into Cocos Creator project/packages
, then you will see the plugin in Project -> LuaCPP Support.