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

  • 相关阅读:
    ASP.NET CORE中控制器内return HTML 内容自动编码问题
    sql server中调用c#写的dll里的方法
    牛腩视频播放管理系统
    apicloud开发笔记
    asp.net core在linux上的部署调试
    C#-微信公众平台接口-上传临时素材
    csc.exe已退出,代码为-532462766
    牛腩记账本core版本源码
    sql server中根据地图经纬度算距离
    ASP.NET CORE做的网站运行在docker上(不用dockerfile文件部署)
  • 原文地址:https://www.cnblogs.com/yssgyw/p/3233285.html
Copyright © 2011-2022 走看看