分类存档: cocos2d-x

收集cocos2dx开发中用的第三方工具

  • UI编辑器

  1. cocosbuilder
  • 粒子编辑器

  1. Particle Designer
  2. ParticleCreator(暂未尝试)
  • 骨骼动画编辑器

  1. spine
  • 艺术字体

  1. Glyph Designer
  2. BMFont (Windows) (这4种暂未使用过)
    Fonteditor
    Hiero
    LabelAtlasCreator

 

cocos2dx中使用粒子特效

// 添加特效

CCParticleSystemQuad* pSystem=CCParticleSystemQuad::create(“test2.plist”);

//pSystem->setBlendAdditive(true);

// pSystem->setPosition(CCPointMake(50, 50));

addChild(pSystem);

pSystem->setAutoRemoveOnFinish(true);

粒子特效可以使用particle desinger来编辑。价格也不贵,才100块钱。

cocos2dx中集成ccbuilder

最小的集成:

需要自定义loader:

class MyCustomCCLayerLoader:public CCLayerLoader{

public:

CCB_STATIC_NEW_AUTORELEASE_OBJECT_METHOD(MyCustomCCLayerLoader, loader);

protected:

CCB_VIRTUAL_NEW_AUTORELEASE_CREATECCNODE_METHOD(HelloLayer); // 这里添加与ccb中定义对应的类

};

加载ccbi代码:

CCNodeLoaderLibrary* library=CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary();

library->registerCCNodeLoader(“HelloLayer”, MyCustomCCLayerLoader::loader());

CCBReader* reader=new CCBReader(library);

reader->autorelease();

pDirector->runWithScene(reader->createSceneWithNodeGraphFromFile(“HelloCocosBuilder.ccbi”));

 

自定义的Layer:

class HelloLayer:public CCLayer,public CCBSelectorResolver,public CCBMemberVariableAssigner,public CCNodeLoaderListener

{

public:

CCLabelTTF* testTTF;

public:

// 点击处理

virtual void pressedClickme(CCObject* target,CCControlEvent* event);

// 这里也没有被调用,原来需要CCNodeLoaderListener,当从ccb文件创建后被调用

virtual void onNodeLoaded(CCNode * pNode, CCNodeLoader * pNodeLoader);

// 设置menuItem的调用

virtual SEL_MenuHandler onResolveCCBCCMenuItemSelector(CCObject * pTarget, CCString * pSelectorName);

// 设置button的调用

virtual SEL_CCControlHandler onResolveCCBCCControlSelector(CCObject * pTarget, CCString * pSelectorName);

// 设置属性

virtual bool onAssignCCBMemberVariable(CCObject * pTarget, CCString * pMemberVariableName, CCNode * pNode);

// 这是做什么用的?

virtual bool init();

// 创建自动释放的本类对象

CREATE_FUNC(HelloLayer);

// 手工释放掉ccb绑定的对象

~HelloLayer(){

CC_SAFE_RELEASE(testTTF);

}

};

void HelloLayer::pressedClickme(CCObject* target, CCControlEvent *event){

CCLog(“clicked pressed click me”);

CCLog(“ttf text:%s”,testTTF->getString());

}

bool HelloLayer::init(){

if(!CCLayer::init()){

CCLog(“invoke hello layer init return false”);

return false;

}

CCLog(“invoke hello layer init return true”);

return true;

}

 

SEL_MenuHandler HelloLayer::onResolveCCBCCMenuItemSelector(CCObject * pTarget, CCString * pSelectorName){

//CCB_SELECTORRESOLVER_CCMENUITEM_GLUE(this, “pressedClickme”, HelloLayer::pressedClickme);

return NULL;

}

 

SEL_CCControlHandler HelloLayer::onResolveCCBCCControlSelector(CCObject* pTarget, CCString* pSelectorName){

CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, “pressedClickme”, HelloLayer::pressedClickme);

return NULL;

}

bool HelloLayer::onAssignCCBMemberVariable(CCObject * pTarget, CCString * pMemberVariableName, CCNode * pNode){

CCB_MEMBERVARIABLEASSIGNER_GLUE(this, “testTTF”, CCLabelTTF*, testTTF);

return false;

}

 

 

void HelloLayer::onNodeLoaded(CCNode * pNode, CCNodeLoader * pNodeLoader){

CCLog(“on node loaded”);

}

cocos2dx tableView

class SongListHeartLayer:public CCLayer,public CCTableViewDelegate,public CCTableViewDataSource
{
public:
virtual bool init();
CREATE_FUNC(SongListHeartLayer);

virtual void scrollViewDidScroll(cocos2d::extension::CCScrollView* view) {};
virtual void scrollViewDidZoom(cocos2d::extension::CCScrollView* view) {}

virtual   void  tableCellTouched(CCTableView* table, CCTableViewCell* cell)  ;

virtual   CCSize  cellSizeForTable(CCTableView *table)  ;
virtual   CCTableViewCell* tableCellAtIndex(CCTableView *table, unsigned int idx) ;
virtual   unsigned int  numberOfCellsInTableView(CCTableView *table)  ;

};

创建tableView

tableView = CCTableView::create(this, CCSizeMake(320,360));
tableView->setDelegate(this);
tableView->setPosition(CCPointMake(0,50));
tableView->setVerticalFillOrder(kCCTableViewFillTopDown);

其它比较重新的代码:

void SongListHeartLayer::tableCellTouched(CCTableView* table,
CCTableViewCell* cell) {

}

CCSize SongListHeartLayer::cellSizeForTable(CCTableView *table) {
return CCSizeMake(320,60);
}

CCTableViewCell* SongListHeartLayer::tableCellAtIndex(CCTableView *table,
unsigned int idx) {

CCTableViewCell* cell = table->dequeueCell();
if (!cell) {
cell = new CCTableViewCell();
cell->autorelease();

//cell->setse
} else {
CCLabelTTF* label = (CCLabelTTF*) cell->getChildByTag(123);
label->setString(str.c_str());
}

return cell;
}

unsigned int SongListHeartLayer::numberOfCellsInTableView(CCTableView *table) {

return musics.size();
}

android ane 创建

参考资料:http://www.adobe.com/cn/devnet/air/articles/building-ane-ios-android-pt1.html

参考资料:http://sswilliam.blog.163.com/blog/static/1896963832011910113320334/

 

cocos2dx自适应分辨率

2.0版本提供了三种适配策略:
kResolutionNoBorder:超出屏幕的部分会被裁剪,两侧没有黑边,铺满屏幕,按图片原始比例显示,图片不变形。
kResolutionShowAll:整个游戏界面是可见的,会按原始比例进行缩放,图片不变形,但两侧可能会留有黑边,不铺满屏幕。
kResolutionExactFit:整个游戏界面是可见的,图片可能会进行拉伸或者压缩处理,铺满屏幕,图片会变形。

以下语句设置适配策略:

CCEGLView::sharedOpenGLView()->setDesignResolutionSize(320,480,kResolutionExactFit);

air android 测试

最初开始是自己下载的air sdk.

结果走了不少弯路,不过还好。

现在终于把air sdk固定在4.6,这样的话,so及其它文件都需要重新进行提取。

晕了,是使用的3.6还是4.6,晕。第二天才发现一直测试的3.6,还没有测试4.6,重新来过,把4.6弄出来。

1、不设置Activity的android:configChanges时,切屏会重新调用各个生命周期,切横屏时会执行一次,切竖屏时会执行两次

 

2、设置Activity的android:configChanges=”orientation”时,切屏还是会重新调用各个生命周期,切横、竖屏时只会执行一次

 

3、设置Activity的android:configChanges=”orientation|keyboardHidden”时,切屏不会重新调用各个生命周期,只会执行onConfigurationChanged方法

4、修改surface显示区域的大小:

FrameLayout.LayoutParams params = new android.widget.FrameLayout.LayoutParams(
200, 200);

m_mainView.setLayoutParams(params);

以下为在eclipse中的创建过程:

1、assets中添加META及swf

2、添加类AppEntry及GetVersionCode

3、添加classes.jar air运行类库

4、添加lib下的air运行库*.so

5、Application.mk中添加:

APP_ABI := armeabi armeabi-v7a x86 用来指定生成哪个版本的so文件。

 

 

swf打包为android app

使用air sdk.

参考文档:

http://help.adobe.com/zh_CN/air/build/WS901d38e593cd1bac1e63e3d128cdca935b-8000.html

http://help.adobe.com/zh_CN/air/build/WS5b3ccc516d4fbf351e63e3d118666ade46-7f72.html

http://help.adobe.com/zh_CN/air/build/WS901d38e593cd1bac-4f1413de12cd45ccc23-8000.html

http://help.adobe.com/en_US/air/build/WSBE9908A0-8E3A-4329-8ABD-12F2A19AB5E9.html

 

java -jar C:\Users\joycube2\Downloads\AIRSDK_Compiler\lib\adt.jar -package -target apk-captive-runtime -storetype jks -keystore cer/android.keystore bin/MyGame.apk src/MyGame-app.xml src/BattleHeroMovieTest.swf assets

如果在windows下报找不到icon的错误,请注意上面指令中最后加上assets路径

 

还有一个重要的参考:

https://code.google.com/p/android-java-air-bridge/w/list

 

 

flash解析小笔记

1、 8.8格式float读取,使用ui16读取后除以256,即可得到对应的float值.

 

cocos2dx私有笔记

第二个程序准备实现在线查看图片

需要使用liburl实现异步读取数据。并且需要准备好对应的服务器端。

实现最基本功能后,还需要实现分类,更好的查看图片,比如分出rosimm之类的分类。

另外要添加上交叉推广,让第一个程序来推广第二个程序。

电子书也可以来开始做了。

1、在vs2010下新建项目,并按f5试试能否运行。

直接提示:

错误    6    error C1083: 无法打开包括文件:“CCApplication.h”: No such file or directory    c:\cocos2d-2.0-x-2.0.4\books\classes\appdelegate.h    4    1    Books.win32

可能是因为机器上安装了vs2008及vs2010等,把cocos2dx模版给安装错了。

查找到:InstallWizardForVS2010.js

使用以下方式安装:打开方式 -> 选择程序 -> 浏览 C:\WINDOWS\system32\wscript.exe

安装后重新生成项目即可。

2、下面把项目转到android上。

1)修改为竖屏:android:screenOrientation=”portrait”

2)删除assets,另新建assets(使用引用,引用Resources目录)