cocos2d/creator_to_cocos2dx

Name: creator_to_cocos2dx

Owner: cocos2d

Description: Creator plugin to support C++& Lua in cocos2d-x

Created: 2017-02-16 03:50:58.0

Updated: 2018-05-17 09:09:22.0

Pushed: 2018-05-11 04:49:57.0

Homepage:

Size: 6693

Language: C++

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Table of Contents generated with DocToc

Creator support for Cocos2d-x

Requirements
Limitations

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:

Supporting JavaScript scripts would be overkill. If you need JavaScript scripting support, just use Creator.

Sample project

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.

Currently support on Mac, iOS, Android and Windows.

How to generate the needed files
Options

You will find:

Header search path

For cpp projects, just add reader into header search path.

For lua projects, add the following header paths:

If developing for Android, can just use existing Android.mk, for example, use the Android.mk into your game's Android.mk like this:

L_PATH := $(call my-dir)

ude $(CLEAR_VARS)

L_MODULE := MyGame_shared

L_MODULE_FILENAME := libMyGame

L_SRC_FILES := hellocpp/main.cpp \
               ../../Classes/AppDelegate.cpp \
               ../../Classes/HelloWorldScene.cpp

L_C_INCLUDES := $(LOCAL_PATH)/../../Classes

OCOS_HEADER_ANDROID_BEGIN
OCOS_HEADER_ANDROID_END


L_STATIC_LIBRARIES := cocos2dx_static
CAL_STATIC_LIBRARIES += creator_reader_lua  # for lua project 
L_STATIC_LIBRARIES += creator_reader   # add dependence

OCOS_LIB_ANDROID_BEGIN
OCOS_LIB_ANDROID_END

ude $(BUILD_SHARED_LIBRARY)

ll import-module,.)
ll import-module, ./../../Classes/reader)  # import module path

If developing with Lua, then need to add CreatorReaderBinding.cpp into plugin's Android.mk.

Using it from C++
ygame.cpp

lude "reader/CreatorReader.h"

 some_function()

creator::CreatorReader* reader = creator::CreatorReader::createWithFilename("creator/scenes/sprites/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);

Using it from lua

Register creator binding codes in c++

lude "reader/lua-bindings/creator_reader_bindings.hpp"



ster_creator_reader_manual(L);

Use in lua

l creatorReader = creator.CreatorReader:createWithFilename('creator/CreatorSprites.ccreator')
torReader:setup()
l scene = creatorReader:getSceneGraph()
irector:getInstance():replaceScene(scene)
How to use ColliderManager

ColliderManager is used to manage collisions. Every scene has an instance of ColliderManager. You can use it like this to listen collision events:

tor::CreatorReader* reader = creator::CreatorReader::createWithFilename("creator/CreatorSprites.ccreator");

ill create the needed spritesheets + design resolution
er->setup();

et the scene graph
e* scene = reader->getSceneGraph();

 colliderManager = scene->getColliderManager();
iderManager->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.

Use the plugin in your Cocos Creator project

You can install the released version from Creator, or you can copy creator_project/packages/creator_luacpp_support into Cocos Creator project/packages, then you will see the plugin in Project -> LuaCPP Support.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.