资源简介

官方提供了Cocos2dx的第三方库,但是采用的是2.x的接口,3.x下面依然是可以使用的,不过在这添加了采用3.x接口封装的方法

资源截图

代码片段和文件信息

//
//  GB2ShapeCache-x.cpp
//  
//  Loads physics sprites created with http://www.PhysicsEditor.de
//  To be used with cocos2d-x
//
//  Generic Shape Cache for box2d
//
//  Created by Thomas Broquist
//
//      http://www.PhysicsEditor.de
//      http://texturepacker.com
//      http://www.code-and-web.de
//  
//  All rights reserved.
//
//  Permission is hereby granted free of charge to any person obtaining a copy
//  of this software and associated documentation files (the “Software“) to deal
//  in the Software without restriction including without limitation the rights
//  to use copy modify merge publish distribute sublicense and/or sell
//  copies of the Software and to permit persons to whom the Software is
//  furnished to do so subject to the following conditions:
//  
//  The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
//  
//  THE SOFTWARE IS PROVIDED “AS IS“ WITHOUT WARRANTY OF ANY KIND EXPRESS OR
//  IMPLIED INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM DAMAGES OR OTHER
//  LIABILITY WHETHER IN AN ACTION OF CONTRACT TORT OR OTHERWISE ARISING FROM
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
//

#include “GB2ShapeCache-x.h“
#include “Box2D/Box2D.h“ 

using namespace cocos2d;

/**
 * Internal class to hold the fixtures
 */
class FixtureDef {
public:
    FixtureDef()
    : next(NULL) {}
    
    ~FixtureDef() {
        delete next;
        delete fixture.shape;
    }
    
    FixtureDef *next;
    b2FixtureDef fixture;
    int callbackData;
};

class BodyDef {
public:
BodyDef()
: fixtures(NULL) {}

~BodyDef() {
if (fixtures)
delete fixtures;
}

FixtureDef *fixtures;
Vec2 anchorPoint;
};

static GB2ShapeCache *_sharedGB2ShapeCache = NULL;

GB2ShapeCache* GB2ShapeCache::sharedGB2ShapeCache(void) {
if (!_sharedGB2ShapeCache) {
_sharedGB2ShapeCache = new GB2ShapeCache();
        _sharedGB2ShapeCache->init();
}

return _sharedGB2ShapeCache;
}

bool GB2ShapeCache::init() {
return true;
}

void GB2ShapeCache::reset() {
std::map::iterator iter;
for (iter = shapeobjects.begin() ; iter != shapeobjects.end() ; ++iter) {
delete iter->second;
}
shapeobjects.clear();
}

void GB2ShapeCache::addFixturesToBody(b2Body *body const std::string &shape) {
std::map::iterator pos = shapeobjects.find(shape);
assert(pos != shapeobjects.end());

BodyDef *so = (*pos).second;

FixtureDef *fix = so->fixtures;
    while (fix) {
        body->CreateFixture(&fix->fixture);
        fix = fix->next;
    }
}

cocos2d::Vec2 GB2ShapeCache::anchorPointForShape(const std::string &shape) 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件        2124  2017-07-14 13:13  GB2ShapeCache-x.h
     文件        7889  2017-07-04 15:25  GLES-Render.cpp
     文件        2177  2016-06-23 15:42  GLES-Render.h
     文件       12011  2017-07-17 09:52  GB2ShapeCache-x.cpp

评论

共有 条评论