cocos2d-x节点(CCPhysicsShape.h)API

本文详细介绍了cocos2d-x中的CCPhysicsShape.h文件中定义的节点API,适合cocos2d-x开发者参考学习。内容来源于http://blog.csdn.net/runaying,并强调了学习的重要性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文来自http://blog.csdn.net/runaying ,引用必须注明出处!

cocos2d-x节点(CCPhysicsShape.h)API

温馨提醒:为了大家能更好学习,强烈推荐大家看看本人的这篇博客 Cocos2d-X权威指南笔记

///cocos2d-x-3.0alpha0/cocos2dx/physics
//模拟现实世界的形状,圆形,链形,段状,对变形.....


#include "CCPhysicsSetting.h"
#ifdef CC_USE_PHYSICS

#ifndef __CCPHYSICS_SHAPE_H__
#define __CCPHYSICS_SHAPE_H__

#include "cocoa/CCObject.h"
#include "cocoa/CCGeometry.h"

NS_CC_BEGIN

class PhysicsShapeInfo;
class PhysicsBody;
class PhysicsBodyInfo;

/** 
 * @brief body 的形状. 你不应该直接创建 PhysicsWorld 对象; 相反,你可以从一个 Scene 对象里面得到它.
 */
class PhysicsShape : public Object
{
public:
    enum class Type
    {
        UNKNOWN,
        CIRCLE,
        BOX,
        POLYGEN,
        EDGESEGMENT,
        EDGEBOX,
        EDGEPOLYGEN,
        EDGECHAIN,
    };
    
public:
    inline PhysicsBody* getBody(){ return _body; }
    inline Type getType() { return _type; }
    
protected:
    bool init(PhysicsBody* body, Type type);
    
    /**
     * @brief PhysicsShape 是 PhysicsBody's 的朋友类 class, 但是所有的子类不是.所以这种方法用于子类从 PhysicsBody 获取 bodyInfo..
     */
    PhysicsBodyInfo* bodyInfo() const;
    
    void addToBody();
    
protected:
    PhysicsShape();
    virtual ~PhysicsShape() = 0;
    
protected:
    PhysicsBody* _body;
    PhysicsShapeInfo* _info;
    Type _type;
    
    friend class PhysicsWorld;
    friend class PhysicsBody;
};

/** A circle shape */           //一个圆形状
class PhysicsShapeCircle : public PhysicsShape
{
protected:
    static PhysicsShapeCircle* create(PhysicsBody* body, float radius, Point offset = Point(0, 0));
    bool init(PhysicsBody* body, float radius, Point offset = Point(0, 0));
    
protected:
    PhysicsShapeCircle();
    virtual ~PhysicsShapeCircle();
    
    friend class PhysicsBody;
};

/** A box shape */      //一个盒子形状
class PhysicsShapeBox : public PhysicsShape
{
protected:
    static PhysicsShapeBox* create(PhysicsBody* body, Size size, Point offset = Point(0, 0));
    bool init(PhysicsBody* body, Size size, Point offset = Point(0, 0));
    
protected:
    PhysicsShapeBox();
    virtual ~PhysicsShapeBox();
    
    friend class PhysicsBody;
};

/** A polygon shape */      //多边形的形状
class PhysicsShapePolygon : public PhysicsShape
{
protected:
    static PhysicsShapePolygon* create(PhysicsBody* body, Point* points, int count, Point offset = Point(0, 0));
    bool init(PhysicsBody* body, Point* points, int count, Point offset = Point(0, 0));
    
protected:
    PhysicsShapePolygon();
    virtual ~PhysicsShapePolygon();
    
    friend class PhysicsBody;
};

/** A segment shape */      //一个段的形状
class PhysicsShapeEdgeSegment : public PhysicsShape
{
protected:
    static PhysicsShapeEdgeSegment* create(PhysicsBody* body, Point a, Point b, float border = 1);
    bool init(PhysicsBody* body, Point a, Point b, float border = 1);
    
protected:
    PhysicsShapeEdgeSegment();
    virtual ~PhysicsShapeEdgeSegment();
    
    friend class PhysicsBody;
};

/** An edge box shape */        //一个边缘是框形状
class PhysicsShapeEdgeBox : public PhysicsShape
{
public:
    static PhysicsShapeEdgeBox* create(PhysicsBody* body, Size size, float border = 0, Point offset = Point(0, 0));
    
protected:
    bool init(PhysicsBody* body, Size size, float border = 1, Point offset = Point(0, 0));
    
protected:
    PhysicsShapeEdgeBox();
    virtual ~PhysicsShapeEdgeBox();
    
    friend class PhysicsBody;
};

/** An edge polygon shape */        //一个边缘是多边形形状
class PhysicsShapeEdgePolygon : public PhysicsShape
{
public:
    static PhysicsShapeEdgePolygon* create(PhysicsBody* body, Point* points, int count, float border = 1);
    
protected:
    bool init(PhysicsBody* body, Point* points, int count, float border = 1);
    
protected:
    PhysicsShapeEdgePolygon();
    virtual ~PhysicsShapeEdgePolygon();
    
    friend class PhysicsBody;
};

/** a chain shape */        //链形
class PhysicsShapeEdgeChain : public PhysicsShape
{
public:
    static PhysicsShapeEdgeChain* create(PhysicsBody* body, Point* points, int count, float border = 1);
    
protected:
    bool init(PhysicsBody* body, Point* points, int count, float border = 1);
    
protected:
    PhysicsShapeEdgeChain();
    virtual ~PhysicsShapeEdgeChain();
    
    friend class PhysicsBody;
};

NS_CC_END
#endif // __CCPHYSICS_FIXTURE_H__

#endif // CC_USE_PHYSICS


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值