#pragma once //避免重复包含
#include "../../../../external/Box2D/Box2D.h"
class Box2dUtils{
public:
static b2Body* createDynamicBody(float posX, float posY, void* userData, b2World* _world){
b2BodyDef ballBodyDef;
ballBodyDef.type = b2_dynamicBody; //
ballBodyDef.position.Set(posX, posX);
ballBodyDef.userData = userData; // 把屏幕中的精灵作为 物理世界中物体的 userData
b2Body* ball = _world ->CreateBody(&ballBodyDef);
return ball;
}
static b2Fixture* createFixture(b2Shape* shape, float density, float friction, float restitution, b2Body* ball ){
b2FixtureDef ballFixDef;
ballFixDef.shape = shape;
ballFixDef.density = density;
ballFixDef.friction = friction;
ballFixDef.restitution = restitution;
return ball->CreateFixture(&ballFixDef);
}
#include "../../../../external/Box2D/Box2D.h"
class Box2dUtils{
public:
static b2Body* createDynamicBody(float posX, float posY, void* userData, b2World* _world){
b2BodyDef ballBodyDef;
ballBodyDef.type = b2_dynamicBody; //
ballBodyDef.position.Set(posX, posX);
ballBodyDef.userData = userData; // 把屏幕中的精灵作为 物理世界中物体的 userData
b2Body* ball = _world ->CreateBody(&ballBodyDef);
return ball;
}
static b2Fixture* createFixture(b2Shape* shape, float density, float friction, float restitution, b2Body* ball ){
b2FixtureDef ballFixDef;
ballFixDef.shape = shape;
ballFixDef.density = density;
ballFixDef.friction = friction;
ballFixDef.restitution = restitution;
return ball->CreateFixture(&ballFixDef);
}
};
设置一个小球的时候,直接调用这个包
b2Body*ball=Box2dUtils::createDynamicBody(420/PTM_RADIO,400/PTM_RADIO,ballSp,m_world);
b2CircleShape circle;
circle.m_radius=(52/2.0f)/PTM_RATIO;
BoxUtils::createFixture(&circle,8.0f,0.3f,0.5f,ball);