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

  • 相关阅读:
    Java连接Mysql数据库异常:Public Key Retrieval is not allowed
    java8的时间段比较处理工具类TimeUtils
    MAVEN最常用的远程仓库
    maven的settings.xml配置阿里云中央仓库
    idea如何将java程序打包成exe可执行文件
    FakerUtil
    Golang内存逃逸是什么?怎么避免内存逃逸?
    10个高效Linux技巧及Vim命令对比[转]
    进程间8种通信方式详解
    基于openresty的URL 断路器/熔断器 -- URL-fuse
  • 原文地址:https://www.cnblogs.com/yssgyw/p/3233285.html
Copyright © 2011-2022 走看看