zoukankan      html  css  js  c++  java
  • 【转】获取Sprite的实际Rect

    判断点击是否点击在了一个精灵上, 其实就是判断一个点是否在一个矩形内。

    cocos2d-x的2.0.2版本可以使用CCRect的函数

    bool CCRect::containsPoint(const CCPoint& point) const来判断。

    找出Sprite的Rect很重要了,简单搜索了下,发现网上普遍没有考虑Sprite的AnchorPoint, 所以导致判断出错。

    CCSprite *sprite = CCSprite::create("test.png");
        CCSize contentSize = sprite->getContentSize();
        CCPoint position = sprite->getPosition();
        CCPoint anchorPoint = sprite->getAnchorPoint();
        CCRect rect = CCRectMake(position.x - anchorPoint.x * contentSize.width , position.y - anchorPoint.y * contentSize.height,contentSize.width, contentSize.height);

    这样就能获取到Sprite真实的Rect

  • 相关阅读:
    09课堂问题整理
    08课堂问题整理
    Eclipse开发工具的编码问题
    【伸手党】需要我帮你Google/百度吗?
    IDEA更改左侧目录层级结构
    IDEA设置类和方法的注释
    一篇系列
    "Notice: unserialize(): Error at offset xx of xxx bytes"错误的处理(转载)
    git push命令每次都要输入用户名和密码的问题处理
    在网站添加qq客服功能
  • 原文地址:https://www.cnblogs.com/yssgyw/p/3233285.html
Copyright © 2011-2022 走看看