Git Product home page Git Product logo

cocos2dx-better's Introduction

!!NOTE!!

I already merged cocos2dx-better code to cocos2d-x v2, here is my new repo: cocos2dx-classical. So, cocos2dx-better is end.

我已开始将cocos2dx-better的代码合并到了cocos2d-x v2中, 新的项目叫cocos2dx-classical, cocos2dx-better将不再维护.

Better Cocos2d-x

As its name suggests, this extension will make cocos2d-x better in many aspect, such as better UI controls, better utilities, better compatibility, and more.

Cocos2d-x is a good engine, but:

  • it lacked some UI controls, or just not good enough
  • it lacked some features and third-party tool support
  • it has bugs and fixing comes too slowly, the worse thing is they are super slow responsive to your pull requests. WTF.

Furthermore, I don't want to modify its code because it may introduce extra work to sync code. Here is my solution: a well-designed extension, without touching cocos2d-x code.

Features

I don't want to list all features because it is too many. The best way to understand what it can do is running its test project. The test project supports ONLY iOS and Android. I don't use Windows a lot so there are some basic features missing for Windows. If you are a Windows guy, do it yourself and GOOD LUCK.

However, even the test project doesn't show all its capabilities. I will add more tests if necessary.

How to use

cocos2dx-better project refers cocos2d-x project. You must clone cocos2d-x repository to a folder named "cocos2d-x", and then clone cocos2dx-better in the same parent folder. Currently it only supports cocos2d-x v2 branch and I don't have a clear plan to migrate to v3.

NOTE: recently they renamed master branch to v2 branch, and third-party libraries are not inclued in cocos2d-x git. You must execute download-deps.py to finish the setup.

For iOS:

  • drag cocos2dx-better project into your project
  • you need set up proper include path, here is mine:
$(SDKROOT)/usr/include/libxml2/
$(SRCROOT)/../../cocos2d-x/cocos2dx/include
$(SRCROOT)/../../cocos2d-x/cocos2dx
$(SRCROOT)/../../cocos2d-x/cocos2dx/platform/ios
$(SRCROOT)/../../cocos2d-x/cocos2dx/kazmath/include
$(SRCROOT)/../../cocos2d-x/extensions (set it recursive)
$(SRCROOT)/../../cocos2dx-better/cocos2dx-better/include 
$(SRCROOT)/../../cocos2d-x/CocosDenshion/include
  • drag libcocos2dx-better.a (in Products folder of cocos2dx-better.xcodeproj) to your target framework list
  • add other necessary frameworks to your project, view test project for the detail list
  • if you encounter objc runtime error, change "Compile Source As" to "Objective-C++". If you have pure c library, create a new target for it

For Android:

  • import cocos2dx-better module in your Android.mk
  • you must set a proper NDK_MODULE_PATH environment, below is my setting:
export C2DX_ROOT=$HOME/Projects/cocos2d-x
export NDK_MODULE_PATH=$C2DX_ROOT:${C2DX_ROOT}/cocos2dx/platform/third_party/android/prebuilt:$HOME/Projects/cocos2dx-better
  • cocos2dx-better has some java code, you must link it in your project. If you use ant to build, you can set source.dir property in local.properties, below is my setting.
source.dir=src;${user.home}/../../${c2dx.root}/cocos2dx/platform/android/java/src;${user.home}/../../${c2dx.root}/../cocos2dx-better/cocos2dx-better/java
  • in Android.mk, you must link cocos2dx-better library with whole archive option, something like below:
... more
LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dx-better
include $(BUILD_SHARED_LIBRARY)
$(call import-module,cocos2dx-better)

You need only to import cocos2dx-better module because cocos2dx-better module already imports cocos2d-x module.

If not clear, refer to demo code.

How to use CCImagePicker

There is a CCImagePicker in cocos2dx-better, it can take image from camera or album and return it in any size. It is very handy, but you need more setup before using it. In iOS, just use it. In Android, don't forget to config something:

  • register activities in AndroidManifest.xml, below is an example, you can change some attribute if you like, such as screenOrientation.
<activity
    android:name="org.cocos2dx.lib.cropimage.CropImage"
    android:configChanges="keyboardHidden|orientation"
    android:screenOrientation="portrait"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
</activity>
<activity
    android:name="org.cocos2dx.lib.ImagePickerActivity"
    android:configChanges="keyboardHidden|orientation"
    android:screenOrientation="portrait"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
</activity>
  • add necessary permission
<uses-permission android:name="android.permission.CAMERA" />
  • add feature declaration
<uses-feature
    android:name="android.hardware.camera"
    android:required="false" />
<uses-feature
    android:name="android.hardware.camera.front"
    android:required="false" />

And that is it! No more settings needed. Easy to use, powerful, view its demo for fun!

Optional

Some optional code or tools is in cocos2dx-better/optional folder. Optional code is not compiled into cocos2dx-better library because they may depend on other components. As regards optional tools, they are my little trickes to handle some weird requirements. However, maybe you have such requirements, who knows.

  • B2DebugDraw: it is box2d debug drawing layer, it requires box2d
  • File templates: it is file templates for Xcode. If you like that, you can copy Templates folder to ~/Library/Developer/Xcode
  • AtlasExtractor: a tool can parse texture atlas and output every single image. Use "-h" to show how to use. The project can be directly run and result can be found in test/output folder
  • exportExcel: it is a tool which can export Excel file into JSON format and C++ class. You can use Ant to build the exportExcel.jar file and directly run it.
  • jsoncpp: it is a modified version of jsoncpp, better support in data format conversion. It is also referenced by classes generated by exportExcel.
  • StoryDesigner: it is a designer tool for screenplay, the script language is Lua. However, the story is mainly described by a set of functions defined in CCStoryCommandSet.h. Here is a test.lua in test folder for your reference.
  • pngc: it is a png compress tool which depends on pngquant, written by python. Just execute python compress.py to see usage

cocos2dx-better's People

Contributors

stubma avatar wsgfz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cocos2dx-better's Issues

Building Error

Hi,I built the code in XCode,but some erros appeared as follow:
In file included from /Users/apple/Documents/project_cocos2dx/TestDemo/cocos2dx-common/cocos2dx-common/src/CCAssetInputStream.cpp:26:
In file included from /Users/apple/Documents/project_cocos2dx/TestDemo/cocos2dx-common/cocos2dx-common/include/CCMoreMacros.h:47:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:8:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:409:1: error: expected unqualified-id
@Class NSString, Protocol;
^

好久没来了

好久没来了,一直很忙,今天来看了下,发现还在更新。
一直用着你的label,真的很不错,也非常感谢,不过现在没怎么跟进了,而且我已经开始转用3.x了,以后有时间希望还可以多交流。

设置颜色

label设置颜色后,图标也会变成该颜色,例如我将字设置成黑色,图标也就变黑了。

Android平台文字颜色问题

[color=ffff0000]红色[/color] 现实出来是白色文字,几乎没有红色痕迹。[color=ff0000ff]蓝色[/color]显示出来时蓝色,什么原因?

label的图标问题

目前label在ios可否将图标和文字的中间部分对齐,目前全部是居下对齐,当图标比较大的时候排版不是很好控制,而且在android上也是这种情况,不能横向居中对齐,目前我想到的是重写ImageSpan,但是效果不理想,而且目前比较严重的就是在ios上设置了w,h或者scale等,显示的效果在android上可能差别很大。

CCRichLabel ,显示不出来

我是这样写的:
CCRichLabelTTF* pRichLab = CCRichLabelTTF::create("Hell[color=ffff0000]o[/color]", "Arial", TITLE_FONT_SIZE);
pRichLab->setPosition(ccp(origin.x + visibleSize.width/2, origin.y + 100));
pRichLab->setColor(ccBLUE);
this->addChild(pRichLab, 10);

CCImage_richlabel_ios.mm line 610 CCImage & CCImage undeclared

I compile it in mac,xcode 5.0.2 and i got the error

file : CCImage_richlabel_ios.mm

static bool _initWithString(const char * pText, CCImage::ETextAlign eAlign, const char * pFontName, int nSize, tImageInfo* pInfo, CCPoint* outShadowStrokePadding, LinkMetaList* linkMetas) {
bool bRet = false;

error info :
Semantic issue Use of undeclared Identifier 'CCImage'; did you mean 'CGImage'

and then I add #include "CCImage.h" #include "CCGemetry.h" in the head!
but it got same error! why?
I am new in mac programming, and this is first time i'am using mac machine!
somebody help me!

iOS project Target Dependency

screen shot 2013-12-09 at 6 38 33 pm

It's better to add target dependency to let Xcode compile sub-project automatically.

Test cpp as well.

Thanks for great work!

label的问题

static CGFloat getAscent(void* refCon) {
Span& span = (Span)refCon;
NSString* name = [NSString stringWithCString:span.imageName
encoding:NSUTF8StringEncoding];
UIImage* image = [s_imageMap objectForKey:name];
return (span.height != 0 ? span.height : (image.size.height * span.scaleY)) * CC_CONTENT_SCALE_FACTOR();
}

static CGFloat getDescent(void* refCon) {
return 0;
}

static CGFloat getWidth(void* refCon) {
Span& span = (Span)refCon;
NSString* name = [NSString stringWithCString:span.imageName
encoding:NSUTF8StringEncoding];
UIImage* image = [s_imageMap objectForKey:name];
return (span.width != 0 ? span.width : (image.size.width * span.scaleX)) * CC_CONTENT_SCALE_FACTOR();
}

要加上* CC_CONTENT_SCALE_FACTOR()吗?

小问题

java文件第333行我改成了这样的判断:
case IMAGE:
{
if(openSpan != null && openSpan.imageName.length() > 0) {
原来只判断了
if(openSpan != null)

Socket issue

Hi stubma,I have some problem in the CCTCPSocket sendData and init.

I found that the socket is in nonblocking mode,so send or recieve can in main thread.
And in sendData method,it just copy the data to the socket m_outBuf, the flush() method called only if the m_outBuf is not enough,.Dose is not in-time?
and in sendData() method :

if(m_outBufLen + size > kCCSocketOutputBufferDefaultSize) {
    flush();
    if(m_outBufLen + size > kCCSocketOutputBufferDefaultSize) {
        destroy();
        return false;
    }
}

if flush() dose not send anything,it may occur EINPROGRESS or EAGAIN,so it will execute:

if(m_outBufLen + size > kCCSocketOutputBufferDefaultSize) {
destroy();
return false;
}

and the socket would destroyed,but EINPROGRESS or EAGAIN is not a really socket error,we should send data when the socket buf writable.

Another issue is CCTCPSocket init method,
When socket created,it will connect to the server,it will blocking in select for blockSec.when create socket in main thread,it will blocking main thread,why not set the blockSec to zero,and check the connect event in Scheduler?

MotionWelder support

Hi,I saw WiEngine support Animation Tool like MotionWelder,Could you port it to cocos2d-x please?

link最好支持userobject

这样更好用,每个link带一个userobject,这样,回调的时候可以准确的判断是哪个link了。
而且,目前的link不支持换行,例如我setDimensions后,就无法支持了。

Crash

你们竟然如此害怕出现问题?没有验证之下,就关闭一个issue?
字体文件:
64beb673-01e0-4534-a957-a70e55c691cf

Post名称:
8158fe4e-582f-4fbd-9e01-c6ceca982701

代码段:
64b149af-9a4f-4af3-bc53-f2b4f6bad0d5

Crash:
465a3551-446d-4f7b-abeb-9a6050d5e399

memory leaks on Android !

我做了个测试,创建一千个CClabelTTF,内存会上涨再下降到原来状态,但是CCRichLabelTTF就不会下降到理想状态,初步判断,android端的实现有内存泄漏的问题,具体原因我正在查找,待会晚上看看能不能找到原因。

One suggestion

image

put these import statments into .mm file will be better~

新bug

目前在安卓上有2个bug,
1.在
......
if(!sizeOnly) {
// save padding
nativeSaveShadowStrokePadding(startX, Math.max(0, height - layout.getHeight() - startY));

            // create bitmap and canvas
            Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
            Canvas c = new Canvas(bitmap);

......
之前还是需要判断width和height的大小,这个我目前就是加上了:
if(width > 0 && height > 0)
的条件解决。
2.如果我使用[color=ff000000][/color],也就是标签中间是空字符,在android上奔溃,现在我没有时间找到原因,不知道你能解决不。

crash after setLinkTarget

setLinkTarget not stable enough,crash on :
function : extractLinkMeta

CGFloat startOffsetX = CTLineGetOffsetForStringIndex(line, linkStart, NULL) / CC_CONTENT_SCALE_FACTOR();

EXC_BAD_ACCESS

Even Just Use Link Tag Will Crash On IOS.

Just Test With: [link bg=3f7f7f7f bg_click=9fffff00]显示[/link]

Crash, Not Crash,Crash,Not Crash,I am crazy....

demo跑不起来... cocos2d-x-2.2

我是cocos2dx新手,下载了您的开源工程,参照README把工程目录放到和"cocos2d-x"同一个父目录下,但是TestCpp跑不起来。
报错信息为:
Undefined symbols for architecture i386:
"CocosDenshion::SimpleAudioEngine::sharedEngine()", referenced from:
cocos2d::CCResourceLoader::CDMusicTask::load() in libcocos2dxcommon.a(CCResourceLoader.o)
cocos2d::CCResourceLoader::CDEffectTask::load() in libcocos2dxcommon.a(CCResourceLoader.o)
"CocosDenshion::SimpleAudioEngine::preloadEffect(char const_)", referenced from:
cocos2d::CCResourceLoader::CDEffectTask::load() in libcocos2dxcommon.a(CCResourceLoader.o)
"CocosDenshion::SimpleAudioEngine::preloadBackgroundMusic(char const_)", referenced from:
cocos2d::CCResourceLoader::CDMusicTask::load() in libcocos2dxcommon.a(CCResourceLoader.o)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

重新把cocos2dx-common的项目文件拖进去依旧报此错误。
是不是静态库的依赖我设置的不对啊?恳请不吝赐教!

Crash

Change The Font File On IOS, CRASH AGAIN!

Just Test With TTF File:http://pan.baidu.com/share/link?shareid=3476960079&uk=2014516696

change name to yahei.ttf, copy toe font dir.
Test with:
CCRichLabelTTF* label = CCRichLabelTTF::create("[font=font/yahei.ttf][color=ffffffff]W[/color]orld![/font]", "Helvetica", 30);

Crash, File :CCImage_richlabel.mm
if(frame)
CFRelease(frame);

YOU SHOULD TEST THE LIB DEEPLY ENOUGH.

关于link的小问题

我看到您在label里面加了CCMenu,这样会不会有点击权限的问题?而且我感觉CCMenu设计的很不好。
我目前的做法是单独继承自您的label,然后在里面让其继承于CCTouchDelegate,这样label其实就可以支持点击了,这时候就可以设置点击事件的回调。至于link,可能就得判断点击位置是不是在label的指定区域,如果在,那么就回调link事件。这样设计的好处是,去掉了CCMenu,不用创建menuitem了。但是又引入了CCTouchDelegate。
其实用CCMenu也ok,但是点击权限不知道好不好控制。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.