コード例 #1
0
ファイル: CAApplication.cpp プロジェクト: Watchet/CrossApp
void CAApplication::createStatsLabel()
{
    CAImage* texture = NULL;
    CAImageCache *ImageCache = CAImageCache::sharedImageCache();

    if( m_pFPSLabel && m_pSPFLabel )
    {
        CC_SAFE_RELEASE_NULL(m_pFPSLabel);
        CC_SAFE_RELEASE_NULL(m_pSPFLabel);
        CC_SAFE_RELEASE_NULL(m_pDrawsLabel);
        ImageCache->removeImageForKey("cc_fps_images");
        CCFileUtils::sharedFileUtils()->purgeCachedEntries();
    }

    CAImagePixelFormat currentFormat = CAImage::defaultAlphaPixelFormat();
    CAImage::setDefaultAlphaPixelFormat(kCAImagePixelFormat_RGBA4444);
    unsigned char *data = NULL;
    unsigned int data_len = 0;
    getFPSImageData(&data, &data_len);

    CCImage* image = new CCImage();
    bool isOK = image->initWithImageData(data, data_len);
    if (!isOK) {
        CCLOGERROR("%s", "Fails: init fps_images");
        return;
    }

    texture = ImageCache->addUIImage(image, "cc_fps_images");
    CC_SAFE_RELEASE(image);

    float factor = CCEGLView::sharedOpenGLView()->getDesignResolutionSize().height / 640.0f;

    m_pFPSLabel = CALabel::createWithFrame(CCRect(0, 0, 100, 32));
    m_pFPSLabel->retain();
    m_pFPSLabel->setScale(factor);
    m_pFPSLabel->setColor(CAColor_blue);
    
    m_pSPFLabel = CALabel::createWithFrame(CCRect(0, 0, 100, 32));
    m_pSPFLabel->retain();
    m_pSPFLabel->setScale(factor);
    m_pSPFLabel->setColor(CAColor_yellow);
    
    m_pDrawsLabel = CALabel::createWithFrame(CCRect(0, 0, 100, 32));
    m_pDrawsLabel->retain();
    m_pDrawsLabel->setScale(factor);
    m_pDrawsLabel->setColor(CAColor_green);
    
    m_pDrawsLabel->setFrameOrigin(ccpAdd(ccp(0, 64*factor), CC_DIRECTOR_STATS_POSITION));
    m_pSPFLabel->setFrameOrigin(ccpAdd(ccp(0, 32*factor), CC_DIRECTOR_STATS_POSITION));
    m_pFPSLabel->setFrameOrigin(CC_DIRECTOR_STATS_POSITION);
    
    CAImage::setDefaultAlphaPixelFormat(currentFormat);
}
コード例 #2
0
ファイル: CCDirector.cpp プロジェクト: chevcat/CrossApp
void CCDirector::createStatsLabel()
{
    CAImage* texture = NULL;
    CAImageCache *ImageCache = CAImageCache::sharedImageCache();

    if( m_pFPSLabel && m_pSPFLabel )
    {
        CC_SAFE_RELEASE_NULL(m_pFPSLabel);
        CC_SAFE_RELEASE_NULL(m_pSPFLabel);
        CC_SAFE_RELEASE_NULL(m_pDrawsLabel);
        ImageCache->removeTextureForKey("cc_fps_images");
        CCFileUtils::sharedFileUtils()->purgeCachedEntries();
    }

    CAImagePixelFormat currentFormat = CAImage::defaultAlphaPixelFormat();
    CAImage::setDefaultAlphaPixelFormat(kCAImagePixelFormat_RGBA4444);
    unsigned char *data = NULL;
    unsigned int data_len = 0;
    getFPSImageData(&data, &data_len);

    CCImage* image = new CCImage();
    bool isOK = image->initWithImageData(data, data_len);
    if (!isOK) {
        CCLOGERROR("%s", "Fails: init fps_images");
        return;
    }

    texture = ImageCache->addUIImage(image, "cc_fps_images");
    CC_SAFE_RELEASE(image);

    /*
     We want to use an image which is stored in the file named ccFPSImage.c 
     for any design resolutions and all resource resolutions. 
     
     To achieve this,
     
     Firstly, we need to ignore 'contentScaleFactor' in 'CCAtlasNode' and 'CCLabelAtlas'.
     So I added a new method called 'setIgnoreContentScaleFactor' for 'CCAtlasNode',
     this is not exposed to game developers, it's only used for displaying FPS now.
     
     Secondly, the size of this image is 480*320, to display the FPS label with correct size, 
     a factor of design resolution ratio of 480x320 is also needed.
     */
    float factor = CCEGLView::sharedOpenGLView()->getDesignResolutionSize().height / 640.0f;

    m_pFPSLabel = CCLabelTTF::create("", "Arial", 24);
    m_pFPSLabel->setAnchorPoint(CCPointZero);
    m_pFPSLabel->retain();
    m_pFPSLabel->setScale(factor);
    m_pFPSLabel->setColor(ccBLUE);
    
    m_pSPFLabel = CCLabelTTF::create("", "Arial", 24);
    m_pSPFLabel->setAnchorPoint(CCPointZero);
    m_pSPFLabel->retain();
    m_pSPFLabel->setScale(factor);
    m_pSPFLabel->setColor(ccYELLOW);
    
    m_pDrawsLabel = CCLabelTTF::create("", "Arial", 24);
    m_pDrawsLabel->setAnchorPoint(CCPointZero);
    m_pDrawsLabel->retain();
    m_pDrawsLabel->setScale(factor);
    m_pDrawsLabel->setColor(ccGREEN);
    
    m_pDrawsLabel->setFrameOrigin(ccpAdd(ccp(0, 64*factor), CC_DIRECTOR_STATS_POSITION));
    m_pSPFLabel->setFrameOrigin(ccpAdd(ccp(0, 32*factor), CC_DIRECTOR_STATS_POSITION));
    m_pFPSLabel->setFrameOrigin(CC_DIRECTOR_STATS_POSITION);
    
    CAImage::setDefaultAlphaPixelFormat(currentFormat);
}