读书人

[cocos2dx开发技艺3]工具CocosBuilder

发布时间: 2013-04-07 12:50:11 作者: rapoo

[cocos2dx开发技巧3]工具CocosBuilder的使用--Box2d



在cocosBuilder中创建一个名为robot的ccb,然后组合组成如下的情况:[cocos2dx开发技艺3]工具CocosBuilder的使用-Box2d
调整各个模块的anchor(Chest除外),这些anchor点将被程序读取,作为joint点。然后导出ccbi文件。在xcode中导入robot.ccbi,然后创建一个robot类,继承于CcbBase类(参见上一片文章《 [cocos2dx开发技巧2]工具CocosBuilder的使用--集成》);覆盖onAssignCCBMemberVariable方法,如下:


导出ccbi,在xcode中导入ccbi,接着创建一个playground类,关联相关属性如下:

在Playground类中,实现如下代码:
#ifndef ShootTheApple_MyWorld_h#define ShootTheApple_MyWorld_h#include "Box2D.h"#define VELOCITY_ITER 8#define POSITION_ITER 1class MyWorld {private:    static b2World* world;public:    static void init() {        if (world!=NULL) {            return;        }        b2Vec2 gravity;        gravity.Set(0.0f, -10.0f);        world = new b2World(gravity);                // Do we want to let bodies sleep?        world->SetAllowSleeping(true);                world->SetContinuousPhysics(true);    }        static b2World* getWorld() {        if(world==NULL) {            init();        }        return world;    }        static void update(float dt) {        getWorld()->Step(dt, VELOCITY_ITER, POSITION_ITER);    }};b2World* MyWorld::world=NULL;#endif






读书人网 >操作系统

热点推荐