void CAApplication::createStatsLabel() { CAImage* image = NULL; CAImageCache *ImageCache = CAImageCache::sharedImageCache(); if( m_pFPSLabel) { CC_SAFE_RELEASE_NULL(m_pFPSLabel); ImageCache->removeImageForKey("cc_fps_images"); CCFileUtils::sharedFileUtils()->purgeCachedEntries(); } unsigned char *data = NULL; unsigned int data_len = 0; getFPSImageData(&data, &data_len); image = CAImage::createWithImageData(data, data_len, "cc_fps_images"); float factor = CCEGLView::sharedOpenGLView()->getDesignResolutionSize().height / 640.0f; m_pFPSLabel = CALabel::createWithFrame(DRect(0, 0, 100, 32)); m_pFPSLabel->retain(); m_pFPSLabel->setScale(factor); m_pFPSLabel->setColor(CAColor_blue); m_pFPSLabel->setFrameOrigin(CC_DIRECTOR_STATS_POSITION); }
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); }