• [Cocos2d-x]节点的尺寸大小


    作为一个CCNode,本身没有大小而言,但是AddChild之后,便有了尺寸的概念。

    Cocos2d-x中对于一个节点的尺寸可以通过以下三个方法获取:

    CCSprite:

    getContentSize();

    获取精灵的逻辑尺寸。此值不受缩放变换影响。即setScale()方法不影响此值

     

    boundingBox().size;

    获取精灵的边框尺寸。此值受到缩放变换影响。

     

    getTexture()->getContentSizeInPixels();

    获取精灵的纹理的像素尺寸。

     

    像素点和逻辑点关系:逻辑点大小 = 像素大小/contentScale

     

    Ex:

        CCSize sizeByContentSize = pBackground->getContentSize();
        CCSize sizeByboundingBox = pBackground->boundingBox().size;
        CCSize sizeByPoints = pBackground->getTexture()->getContentSizeInPixels();
        
        CCLOG("sizeByContentSize:%f height:%f",sizeByContentSize.width,sizeByContentSize.height);
        CCLOG("sizeByboundingBox:%f height:%f",sizeByboundingBox.width,sizeByboundingBox.height);
        CCLOG("sizeByPoints:%f height:%f",sizeByPoints.width,sizeByPoints.height);
    
        pBackground->setScale(2);
        CCLOG("转变后:");
        
        sizeByContentSize = pBackground->getContentSize();
        sizeByboundingBox = pBackground->boundingBox().size;
        sizeByPoints =pBackground->getTexture()->getContentSizeInPixels();
        
        CCLOG("sizeByContentSize:%f height:%f",sizeByContentSize.width,sizeByContentSize.height);
        CCLOG("sizeByboundingBox:%f height:%f",sizeByboundingBox.width,sizeByboundingBox.height);
        CCLOG("sizeByPoints:%f height:%f",sizeByPoints.width,sizeByPoints.height);
    

    输出结果:

    Cocos2d: sizeByContentSize:114.000000 height:114.000000

    Cocos2d: sizeByboundingBox:114.000000 height:114.000000

    Cocos2d: sizeByPoints:114.000000 height:114.000000

    Cocos2d: 转变后:

    Cocos2d: sizeByContentSize:114.000000 height:114.000000

    Cocos2d: sizeByboundingBox:228.000000 height:228.000000

    Cocos2d: sizeByPoints:114.000000 height:114.000000

    人生就是一局不能Again的DOTA
  • 相关阅读:
    Project2016下载安装密钥激活教程破解
    关于 Level 和 Promotion,其实就那么简单
    Docker 入门
    Spring Cloud Config中文文档
    如何合理设置线程池大小
    java中线程池的使用
    快速掌握和使用Flyway
    duilib教程之duilib入门简明教程6.XML配置界面
    duilib教程之duilib入门简明教程5.自绘标题栏
    duilib教程之duilib入门简明教程4.响应按钮事件
  • 原文地址:https://www.cnblogs.com/hellenism/p/3472639.html
Copyright © 2020-2023  润新知