zoukankan      html  css  js  c++  java
  • cocos2dx :getBoundingBox getContentSize getTextureRect

    这是cocos2d-x代码看注释的解释 翻译的 不到之处谅解 后面在总结
    getBoundingBox  // 返回一个AABB(axis-aligned bounding-box)在其父母的坐标系统。Returns an AABB (axis-aligned bounding-box) in its parent's coordinate system.
    getContentSize  //节点容量大小
    getTextureRect //返回精灵矩形的点

    {
    图片 Icon-48.png  这种图片 48 × 48 pixels 标准icon中得一个 
        Sprite *pSpBox=Sprite::create("Icon-48.png");
        pSpBox->setPosition(Vec2(m_pWinSize.width*0.5, m_pWinSize.height*0.5));
        pSpBox->setScale(0.2f);
        addChild(pSpBox);
        {
            CCLOG("A");
            Rect rect=pSpBox->getBoundingBox();
            Size size=pSpBox->getContentSize();
            Rect sizea=pSpBox->getTextureRect();
            CCLOG("BoundingBox(%f,%f,%f,%f)",rect.origin.x,rect.origin.y,rect.size.width,rect.size.height);
            CCLOG("ContentSize(%f,%f)",size.width,size.height);
            CCLOG("TextureRect(%f,%f,%f,%f)",sizea.origin.x,sizea.origin.y,sizea.size.width,sizea.size.height);
        }
        pSpBox->setScale(0.5f);
        {
            CCLOG("B");
            Rect rect=pSpBox->getBoundingBox();
            Size size=pSpBox->getContentSize();
            Rect sizea=pSpBox->getTextureRect();
            CCLOG("BoundingBox(%f,%f,%f,%f)",rect.origin.x,rect.origin.y,rect.size.width,rect.size.height);
            CCLOG("ContentSize(%f,%f)",size.width,size.height);
            CCLOG("TextureRect(%f,%f,%f,%f)",sizea.origin.x,sizea.origin.y,sizea.size.width,sizea.size.height);
        }
    cocos2d: A
    cocos2d: BoundingBox(475.200012,315.200012,9.600006,9.600006)
    cocos2d: ContentSize(48.000000,48.000000)
    cocos2d: TextureRect(0.000000,0.000000,48.000000,48.000000)
    cocos2d: B
    cocos2d: BoundingBox(468.000000,308.000000,24.000000,24.000000)
    cocos2d: ContentSize(48.000000,48.000000)
    cocos2d: TextureRect(0.000000,0.000000,48.000000,48.000000)
    }

    getBoundingBox  中得 Size.width .height  显示图片真实大小 (考虑缩放和不缩放)
    getContentSize  纹理图片大小
    getTextureRect  当前的纹理在总纹理的位置 (不考虑 缩放不缩放)
    图片有缩放 就用 getBoundingBox ,不考虑缩放用 getContentSize

  • 相关阅读:
    P3952 [NOIP2017 提高组] 时间复杂度
    1905. 统计子岛屿
    1102 Invert a Binary Tree (25 分)
    P1077 [NOIP2012 普及组] 摆花
    P3915 树的分解
    P1045 [NOIP2003 普及组] 麦森数
    P4961 小埋与扫雷
    P1123 取数游戏
    P1460 [USACO2.1]健康的荷斯坦奶牛 Healthy Holsteins
    CF1059B Forgery
  • 原文地址:https://www.cnblogs.com/aibox222/p/8676139.html
Copyright © 2011-2022 走看看