cocos2dx 下的CCRect

本文详细介绍了Cocos2d-x中CCRect类的使用方法,包括构造函数、成员变量、常用方法如获取边界值、比较矩形是否相等及包含点等,并给出了CCRectMake宏定义及CCRectZero的使用示例。

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

 

刚开始写cocos2dx,对一些东西还是很不熟悉,CCRect的用法就不感冒

先下来,省的忘记~~~


class CC_DLL CCRect : public CCObject
{
public:
    //CCRect的原点
    CCPoint origin;
    //CCRect的大小
    CCSize  size;

public:
    //构造函数
    CCRect(); 
    CCRect(float x, float y, float width, float height);    
    CCRect(const CCRect& other);
    //意思是: = 操作就是从另一个CCRect的值赋给自己?
    CCRect& operator= (const CCRect& other); 
    //设置其origin 以及 size
    void setRect(float x, float y, float width, float height);
    virtual CCObject* copyWithZone(CCZone* pZone);
    //获取X最小值
    float getMinX() const; /// return the leftmost x-value of current rect
    //获取X中间值
    float getMidX() const; /// return the midpoint x-value of current rect
    //获取X最大值
    float getMaxX() const; /// return the rightmost x-value of current rect
    //获取Y最小值
    float getMinY() const; /// return the bottommost y-value of current rect
    //获取Y中间值
    float getMidY() const; /// return the midpoint y-value of current rect
    //获取最大Y值
    float getMaxY() const; /// return the topmost y-value of current rect
    //比较两个CCRect是否吻合
    bool equals(const CCRect& rect) const;  
    //是否包含某点,在边上也算的
    bool containsPoint(const CCPoint& point) const;
    //是否相交
    bool intersectsRect(const CCRect& rect) const;
    
public:
    /** @deprecated use CCRect::equals(const CCRect&) instead, like r1.equals(r2) */
    //比较两个CCRect是否吻合
    CC_DEPRECATED_ATTRIBUTE static bool CCRectEqualToRect(const CCRect& rect1, const CCRect& rect2);
    /** @deprecated use CCRect::containsPoint(const CCPoint&) instead, like rect.containsPoint(point) */
    //CCRect是否包含某点
    CC_DEPRECATED_ATTRIBUTE static bool CCRectContainsPoint(const CCRect& rect, const CCPoint& point);
    /** @deprecated use CCRect::intersectsRect(const CCRect&) instead, like r1.intersectsRect(r2) */
    //两个CCRect是否相交
    CC_DEPRECATED_ATTRIBUTE static bool CCRectIntersectsRect(const CCRect& rectA, const CCRect& rectB);
};

//定义CCRectMake方法,等同CCRect构造方法
#define CCRectMake(x, y, width, height) CCRect((float)(x), (float)(y), (float)(width), (float)(height))

/* The "zero" rectangle -- equivalent to CCRectMake(0, 0, 0, 0). */ 
//定义CCRectZero,等同构造一个origin size都为0的CCRect
const CCRect CCRectZero = CCRectMake(0,0,0,0);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值