#ifndef __B2COMPONENT_H__ #define __B2COMPONENT_H__ // C and C++ headers // cocos2d-x headers // project headers #include "GameManager.h" #include "GameObject.h" class B2Component : public cocos2d::Component { public: static B2Component* createBody(cocos2d::Node* owner, b2World** world,std::string nameOfBody); static B2Component* createBody(cocos2d::Node* owner, b2World** world, std::string nameOfBody, std::string fixtureId, cocos2d::Vec2 localPosition, float angle); static B2Component* createCircleBody(cocos2d::Node* owner, b2World** world, std::string nameOfBody); inline b2Body* getBody(){return _body;}; void setBodyTransForm(float x, float y , float angle) { _positionX = x; _positionY = y; _angle = angle; } void beginContact(GameObject* otherObject, b2Contact* contact); b2FixtureDef getFixtureDefsFromPhysicsEditor(const cocos2d::ValueMap &dict, const std::string &bodyName, std::string fixtureId, float scaleFactor, b2PolygonShape &ps, b2CircleShape& cs); protected: B2Component(cocos2d::Node* owner,b2World** world); ~B2Component(); b2World** _world; virtual bool init(std::string name, std::string fixtureId); virtual bool init(std::string name, std::string fixtureId, cocos2d::Vec2 localPosition, float angle); virtual bool initCircle(std::string name); void update(float delta)override; void onRemove() override; b2Body* _body; float _positionX = 0.f; float _positionY = 0.f; float _angle = 0.f; }; #endif // __B2COMPONENT_H__