Cocos2d-x简单Box2d代码示例|点击碰撞>HelloWorldScene.h

#ifndef __HELLOWORLD_SCENE_H__

#define __HELLOWORLD_SCENE_H__


#include "cocos2d.h"

#include "Box2D.h"

using namespace cocos2d;


class HelloWorld : public CCLayer{

public:

    

    HelloWorld();

    ~HelloWorld();

    static CCScene* scene();

    

    void initPhysics();

    void addNewSpriteAtPosition(CCPoint point);

    

    virtual void draw();

    virtual void ccTouchesEnded(CCSet *touches,CCEvent *event);

    void update(float dt);//更新box2d

    

private:

    

    b2World *world;

    CCTexture2D *m_pSpriteTexture;//weak ref

    

};


//动作精灵

class PhysicsSprite:public CCSprite {

    

public:

    PhysicsSprite();

    void setPhysicsBody(b2Body *body);

    virtual bool isDirty(void);

    virtual CCAffineTransform nodeToParentTransform(void);

private:

    b2Body *m_pBody;//Strong Def

};



你可能感兴趣的:(Cocos2d-x)