Example #1
0
bool GameUtil::resizeImage(const char* szInFile, const char* szOutFile, int width, int height)
{
	CCLog("GameUtil::resizeImage - [path:%s] [W:%d] [H:%d]", szInFile, width, height);
	CCSprite* pOrg = CCSprite::create(szInFile);
	CCSize orgSize = pOrg->getContentSize();

	float fScaleX = (float)width / orgSize.width;
	float fScaleY = (float)height / orgSize.height;
	float fScale = max(fScaleX, fScaleY);

	CCPoint ptCenter = ccp(width/2, height/2);

	// 세로 사진은 가로로 방향을 변경
	if (orgSize.width < orgSize.height) {
		pOrg->setRotation(90.0f);
		ptCenter = ccp(height/2, width/2);
	}

	CCRenderTexture * rt = CCRenderTexture::create(width, height);
 
	pOrg->setPosition(ptCenter);
	pOrg->setAnchorPoint(ccp(0.5f, 0.5f));
	pOrg->setScale(fScale);
 
    rt->begin();
    pOrg->visit();
    rt->end();
	
	// 파일로 저장
	bool bSave = rt->saveToFile(szOutFile);

	return bSave;
}
Example #2
0
CCRenderTexture * Utils::fontCreateStroke(CCLabelTTF * label,float size, ccColor3B color){
    
    CCRenderTexture *rt = CCRenderTexture::create((int)label->getTexture()->getContentSize().width, (int)label->getTexture()->getContentSize().height);
    CCPoint originalPos = label->getPosition();
    ccColor3B originalColor = label->getColor();
    bool originalVisibility = label->isVisible();

    label->setColor(color);
    
    ccBlendFunc originalBlend = label->getBlendFunc();
    label->setBlendFunc((ccBlendFunc){ GL_SRC_ALPHA, GL_ONE });
    //CCPoint center = ccp(label->getTexture()->getContentSize().width/2 + size, label->getTexture()->getContentSize().height/2 + size); //shadow effect offset
    
    CCPoint center = ccp(label->getTexture()->getContentSize().width/2, label->getTexture()->getContentSize().height/2);
    
    rt->begin();
    
    for(int i = 0; i<360; i+=30){
        label->setPosition(ccp(center.x + sin(CC_DEGREES_TO_RADIANS(i)) * size, center.y + cos(CC_DEGREES_TO_RADIANS(i)) * size));
        label->visit();
    }
    
    rt->end();
    
    label->setPosition(originalPos);
    label->setColor(originalColor);
    label->setBlendFunc(originalBlend);
    label->setVisible(originalVisibility);
    
    rt->setPosition(originalPos);
    
    return rt;
}
Example #3
0
CCSprite* GameUtil::mergeSprite(CCSprite* pOrg1, CCSprite* pOrg2)
{
	CCPoint ptOrg1(pOrg1->getPosition());
	CCPoint ptOrg2(pOrg2->getPosition());

	CCRenderTexture * rt = CCRenderTexture::create((int)pOrg1->getContentSize().width, (int)pOrg1->getContentSize().height);
 
	pOrg1->setPosition(ccp(pOrg1->getContentSize().width/2, pOrg1->getContentSize().height/2));
	pOrg2->setPosition(ccp(pOrg2->getContentSize().width/2, pOrg2->getContentSize().height/2));
 
    rt->begin();
    pOrg1->visit();
    pOrg2->visit();
    rt->end();
	
	pOrg1->setPosition(ptOrg1);
	pOrg2->setPosition(ptOrg2);

	CCSprite *retSprite = CCSprite::createWithTexture(rt->getSprite()->getTexture());
	retSprite->setFlipY(true);

	//CCSize sisze1 = retSprite->getContentSize();
	//CCSize size2 = retSprite->getTexture()->getContentSize();

	// debugging : 파일로 저장
	//string sPath = CCFileUtils::sharedFileUtils()->getWriteablePath();
	//sPath.c_str();
	//char szSave[MAX_PATH];
	//sprintf(szSave, "%ssave.png", sPath.c_str());
	//bool bSave = rt->saveToFile(szSave);

	return retSprite;
}
static CCString ScreenShoot()
{
	CCSize size = CCDirector::sharedDirector()->getWinSize();  
	//定义一个屏幕大小的渲染纹理  
	CCRenderTexture* pScreen = CCRenderTexture::create(size.width,size.height, kCCTexture2DPixelFormat_RGBA8888);  
	//获得当前的场景指针  
	CCScene* pCurScene = CCDirector::sharedDirector()->getRunningScene();  
	//渲染纹理开始捕捉  
	pScreen->begin();  
	//当前场景参与绘制  
	pCurScene->visit();  
	//结束捕捉  
	pScreen->end();  
	char szfile[1024]={0};
	//string   pathToSave = "/sdcard/download/";//

	string pathToSave = "ScreenShoot.png";
	//sprintf(szfile,"%s%s",pathToSave.c_str(),"share.png");
	//保存为png
	if(pScreen->saveToFile(pathToSave.c_str(), kCCImageFormatPNG))
	{
		//CCMessageBox("saveToFile ok!", "saveToFile ok!");
	}
	pathToSave = CCFileUtils::sharedFileUtils()->getWritablePath()+pathToSave;
	//保存为jpg
	//pScreen->saveToFile("XXXXXX.jpg", kCCImageFormatJPEG);  
	CC_SAFE_DELETE(pScreen); 

	return pathToSave.c_str();
}
void RenderTextureZbuffer::renderScreenShot()
{
	CCRenderTexture *texture = CCRenderTexture::renderTextureWithWidthAndHeight(512, 512);
	if (NULL == texture)
	{
		return;
	}
	texture->setAnchorPoint(ccp(0, 0));
	texture->begin();

	this->visit();

	texture->end();

	CCSprite *sprite = CCSprite::spriteWithTexture(texture->getSprite()->getTexture());

	sprite->setPosition(ccp(256, 256));
	sprite->setOpacity(182);
	sprite->setFlipY(1);
	this->addChild(sprite, 999999);
	sprite->setColor(ccGREEN);

	sprite->runAction(CCSequence::actions(CCFadeTo::actionWithDuration(2, 0),
		                                  CCHide::action(),
		                                  NULL));
}
Example #6
0
//ÔÝÍ£
void CGameControler::PauseGame(int _type){
	CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
	CCRenderTexture *renderTexture = CCRenderTexture::create(visibleSize.width,visibleSize.height);
	renderTexture->begin(); 
	this->getParent()->visit();
	renderTexture->end();
	CCDirector::sharedDirector()->pushScene(Gamepause::scene(renderTexture));
}
Example #7
0
void AsMessageBox::initShareMessageBox(int subType){
    
    if(!MainUser->muted)
        CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("openFrame.wav");
    
    shareImageIndex = subType;
    
    //1.截屏
    if (subType == 1) {
        CCRenderTexture* pScreen = CCRenderTexture::create(winSize.width,winSize.height);
        CCScene* pCurScene = CCDirector::sharedDirector()->getRunningScene();
        pScreen->begin();
        pCurScene->visit();
        pScreen->end();
        pScreen->saveToFile("shared.png",kCCImageFormatPNG);
    }

    //2.黑色底层
    cover = CCLayerColor::create(ccc4(0,0,0,200));
    cover->setPosition(CCPointZero);
    addChild(cover,0);
    
    //3.提示框底层
    showbox = CCSprite::createWithSpriteFrameName("shareFrame.png");
    showbox->setScaleY(1.1);
    showbox->setPosition(ccp(size.width/2,size.height/2+winDif*2*alpha));
    cover->addChild(showbox,1);
    
    //4.提示框上的文字
    CCSprite* shareWeixinSprite = CCSprite::createWithSpriteFrameName("shareWeixin.png");
    CCSprite* shareWeixinSprite_s = CCSprite::createWithSpriteFrameName("shareWeixin-s.png");
    CCSprite* shareWeixin1Sprite = CCSprite::createWithSpriteFrameName("shareWeixin1.png");
    CCSprite* shareWeixin1Sprite_s = CCSprite::createWithSpriteFrameName("shareWeixin1-s.png");
    CCSprite* closeSprite = CCSprite::createWithSpriteFrameName("closeMatchTable.png");
    CCSprite* closeSprite_s = CCSprite::createWithSpriteFrameName("closeMatchTable-s.png");
    CCMenuItemSprite* closeItem = CCMenuItemSprite::create(closeSprite,closeSprite_s,this,menu_selector(AsMessageBox::closeMessageBox));
    CCMenuItemSprite* item1 = CCMenuItemSprite::create(shareWeixinSprite,shareWeixinSprite_s,this,menu_selector(AsMessageBox::goShare));
    CCMenuItemSprite* item2 = CCMenuItemSprite::create(shareWeixin1Sprite,shareWeixin1Sprite_s,this,menu_selector(AsMessageBox::goShare));
    item1->setTag(10);
    item2->setTag(11);
    item1->setPosition(ccp(size.width*18/50,size.height*10/20+winDif*2.18*alpha));
    item2->setPosition(ccp(size.width*32/50,size.height*10/20+winDif*2.18*alpha));
    closeItem->setPosition(ccp(size.width*5.7/7,size.height*11.5/20+winDif*2.18*alpha));
    closeMenu = CCMenu::create(item1,item2,closeItem,NULL);
    closeMenu->setPosition(CCPointZero);
    addChild(closeMenu,2);
    
    //5.文字提示
    CCLabelTTF* shareToIndiLabel = CCLabelTTF::create("分享给朋友","Arial Rounded MT Bold",24);
    CCLabelTTF* shareToCircleLabel = CCLabelTTF::create("分享到朋友圈","Arial Rounded MT Bold",24);
    shareToIndiLabel->setColor(ccc3(55, 55, 55));
    shareToCircleLabel->setColor(ccc3(55, 55, 55));
    shareToIndiLabel->setPosition(ccp(size.width*18/50,size.height*8/20+winDif*2.18*alpha));
    shareToCircleLabel->setPosition(ccp(size.width*32/50,size.height*8/20+winDif*2.18*alpha));
    addChild(shareToIndiLabel,7,53);
    addChild(shareToCircleLabel,7,54);
    
}
Example #8
0
    CCRenderTexture* UILabelTTF::createStroke(CCLabelTTF* label, float size ,ccColor3B cor)
    {
        float RealSize = size;
        if(label == NULL || label->getTexture() == NULL)
        {
            return NULL;
        }
		label->setAnchorPoint(ccp(0.5, 0.5));
        CCRenderTexture* rt = CCRenderTexture::create(label->getContentSize().width + RealSize*2, label->getContentSize().height + RealSize*2);
		rt->setAnchorPoint(ccp(0.0,0.0));
		rt->setPosition(0,0);
        if(rt->getSprite() && rt->getSprite()->getTexture())
        {
            rt->getSprite()->getTexture()->setAntiAliasTexParameters();
			rt->getSprite()->setOpacityModifyRGB(true);
        }
		else
		{
			CCLog("UILabelTTF null texture");
		}

		CCPoint originalPos = label->getPosition();
		ccColor3B originalColor = label->getColor();
		bool originalVisibility = label->isVisible();
		label->setColor(cor);
		label->setVisible(true);
		ccBlendFunc originalBlend = label->getBlendFunc();
		ccBlendFunc tBlendFunc = {GL_SRC_ALPHA, GL_ONE };
		label->setBlendFunc(tBlendFunc);

		rt->clear(0, 0, 0, 0);
		CCPoint center = ccp(label->getContentSize().width/2 ,label->getContentSize().height /2 );
		rt->begin();
		label->setPosition(ccp(center.x, center.y - RealSize));
		label->visit();
		label->setPosition(ccp(center.x + 2*RealSize, center.y - 2*RealSize));
		label->visit();
		label->setPosition(ccp(center.x + RealSize, center.y));
		label->visit();
		label->setPosition(ccp(center.x + 2*RealSize, center.y - RealSize));
		label->visit();
		label->setColor(originalColor);
		label->setPosition(ccp(center.x,center.y));
		label->visit();
		rt->end();

        label->setBlendFunc(originalBlend);
        label->setVisible(originalVisibility);
        label->setPosition(originalPos);

		// for test
		//char file[100];
		//sprintf(file,"../../temp/%s_creat.png",label->getString());
		//rt->saveToFile(file,kCCImageFormatPNG);
        return rt;
    }
Example #9
0
void GameScene::onPause(cocos2d::CCObject *pSender)
{
	pPauseMenu->setVisible(false);
	CCRenderTexture *renderTexture = CCRenderTexture::create(SCREEN_WIDTH, SCREEN_HEIGHT);
    renderTexture->begin();
    this->getParent()->visit();
    renderTexture->end();  //这里实际是通过CCRenderTexture保存当前界面(相当于截屏),然后传递给暂停界面,当成背景精灵
	pPauseMenu->setVisible(true);
    CCDirector::sharedDirector()->pushScene(PauseScene::scene(renderTexture,true));
}
Example #10
0
bool HelloWorld::init()
{
    if ( !CCLayer::init() )
    {
        return false;
    }

    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

    CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
                                      "CloseNormal.png",
                                      "CloseSelected.png",
                                      this,
                                      menu_selector(HelloWorld::menuCloseCallback));

    pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 ,
                                origin.y + pCloseItem->getContentSize().height/2));

    CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
    pMenu->setPosition(CCPointZero);
    this->addChild(pMenu, 1);

    CCSize size = CCDirector::sharedDirector()->getWinSize();

#if 0
    CCLayerColor *colorLayer = CCLayerColor::create(ccc4(0,80,80,255));
    addChild(colorLayer);

    CCSprite *spr_premulti = CCSprite::create("Ball.png");
    spr_premulti->setPosition(ccp(16,48));

    CCSprite *spr_nonpremulti = CCSprite::create("Ball.png");
    spr_nonpremulti->setPosition(ccp(16,16));


    CCRenderTexture *rend = CCRenderTexture::create(32, 64, kCCTexture2DPixelFormat_RGBA8888);

    if (rend == NULL)
        exit(0);

    rend->begin();
    spr_premulti->visit();
    spr_nonpremulti->visit();
    rend->end();

    addChild(spr_nonpremulti);
    addChild(spr_premulti);
    addChild(rend);
#endif

	scheduleUpdate();

    return true;
}
RenderTextureIssue937::RenderTextureIssue937()
{
    /*
    *     1    2
    * A: A1   A2
    *
    * B: B1   B2
    *
    *  A1: premulti sprite
    *  A2: premulti render
    *
    *  B1: non-premulti sprite
    *  B2: non-premulti render
    */
    CCLayerColor *background = CCLayerColor::layerWithColor(ccc4(200,200,200,255));
    addChild(background);

    CCSprite *spr_premulti = CCSprite::spriteWithFile("Images/fire.png");
    spr_premulti->setPosition(ccp(16,48));

    CCSprite *spr_nonpremulti = CCSprite::spriteWithFile("Images/fire.png");
    spr_nonpremulti->setPosition(ccp(16,16));


    /* A2 & B2 setup */
    CCRenderTexture *rend = CCRenderTexture::renderTextureWithWidthAndHeight(32, 64);

	if (NULL == rend)
	{
		return;
	}

    // It's possible to modify the RenderTexture blending function by
    //		[[rend sprite] setBlendFunc:(ccBlendFunc) {GL_ONE, GL_ONE_MINUS_SRC_ALPHA}];

    rend->begin();
    spr_premulti->visit();
    spr_nonpremulti->visit();
    rend->end(); 

    CCSize s = CCDirector::sharedDirector()->getWinSize();

    /* A1: setup */
    spr_premulti->setPosition(ccp(s.width/2-16, s.height/2+16));
    /* B1: setup */
    spr_nonpremulti->setPosition(ccp(s.width/2-16, s.height/2-16));

    rend->setPosition(ccp(s.width/2+16, s.height/2));

    addChild(spr_nonpremulti);
    addChild(spr_premulti);
    addChild(rend);
}
Example #12
0
void CCTransitionRadialCCW::onEnter()
{
	CCTransitionScene::onEnter();
	// create a transparent color layer
	// in which we are going to add our rendertextures
	CCSize size = CCDirector::sharedDirector()->getWinSize();

	// create the second render texture for outScene
	CCRenderTexture *outTexture = CCRenderTexture::renderTextureWithWidthAndHeight((int)size.width, (int)size.height);

	if (NULL == outTexture)
	{
		return;
	}
	
	outTexture->getSprite()->setAnchorPoint(ccp(0.5f,0.5f));
	outTexture->setPosition(ccp(size.width/2, size.height/2));
	outTexture->setAnchorPoint(ccp(0.5f,0.5f));

	// render outScene to its texturebuffer
	outTexture->clear(0,0,0,1);
	outTexture->begin();
	m_pOutScene->visit();
	outTexture->end();

	//	Since we've passed the outScene to the texture we don't need it.
	this->hideOutShowIn();

	//	We need the texture in RenderTexture.
	CCProgressTimer *outNode = CCProgressTimer::progressWithTexture(outTexture->getSprite()->getTexture());
	// but it's flipped upside down so we flip the sprite
	outNode->getSprite()->setFlipY(true);
	//	Return the radial type that we want to use
	outNode->setType(radialType());
	outNode->setPercentage(100.f);
	outNode->setPosition(ccp(size.width/2, size.height/2));
	outNode->setAnchorPoint(ccp(0.5f,0.5f));

	// create the blend action
	CCAction * layerAction = CCSequence::actions
	(
		CCProgressFromTo::actionWithDuration(m_fDuration, 100.0f, 0.0f),
		CCCallFunc::actionWithTarget(this, callfunc_selector(CCTransitionScene::finish)),
		NULL
	);
	// run the blend action
	outNode->runAction(layerAction);

	// add the layer (which contains our two rendertextures) to the scene
	this->addChild(outNode, 2, kSceneRadial);
}
Example #13
0
    static CCSprite* createMaskSprite(CCLayerColor* base,
                                      const std::vector<CCRect>& cutoutList)
    {
        CCSize winSize = CCDirector::sharedDirector()->getWinSize();
        
//        CCRenderTexture* rt = CCRenderTexture::create(winSize.width, winSize.height);
        
        // use a low-precision format
        CCRenderTexture* rt = CCRenderTexture::create(winSize.width,
                                                      winSize.height,
                                                      kTexture2DPixelFormat_RGBA8888);
        rt->setAnchorPoint(ccp(0, 0));
        rt->setPosition(ccp(0, 0));
        
        ccBlendFunc cutoutBlend = {GL_DST_ALPHA, GL_ZERO};
        
        // render to texture
        rt->begin();
        base->visit();

        CCSprite* s = CCSprite::create("ui/1x1_b.png");
        s->setAnchorPoint(ccp(0, 0));
        s->setOpacity(0);
        
        for(const CCRect& cutout : cutoutList)
        {
            s->setPosition(cutout.origin);
            s->setScaleX(cutout.size.width * contentScale());
            s->setScaleY(cutout.size.height * contentScale());

            s->setBlendFunc(cutoutBlend);
            s->visit();
        }
        rt->end();
        // render to texture done
        
        std::string randName = std::string("mask_image_") + boost::lexical_cast<std::string>(rand());

        CCImage* img = rt->newCCImage(false);
        img->autorelease();
        
        CCTexture2D* tex = CCTextureCache::sharedTextureCache()->addUIImage(img,
                                                                            randName.c_str());
        CCSprite *mask = CCSprite::createWithTexture(tex);
        mask->setFlipY(true);
        mask->setAnchorPoint(ccp(0, 0));
        mask->setPosition(ccp(0, 0));
        
        return mask;
    }
Example #14
0
void FeedAPIScene::postPhotoInUserAlbum()
{
    CCRenderTexture *render = CCRenderTexture::create(AppDelegate::SCREEN_WIDTH, AppDelegate::SCREEN_HEIGHT);
    render->setPosition(ccp(AppDelegate::SCREEN_WIDTH / 2, AppDelegate::SCREEN_HEIGHT / 2));
    render->begin();
    CCDirector::sharedDirector()->getRunningScene()->visit();
    render->end();
    render->saveToFile("ScreenShot.jpg", kCCImageFormatJPEG);
    
    std::string filePathName = CCFileUtils::sharedFileUtils()->getWritablePath().append("ScreenShot.jpg");
    
    
    EziSocialObject::sharedObject()->postPhoto(filePathName.c_str(), "This is photo test message");
    //EziSocialObject::sharedObject()->postPhoto("ball.png", "This is photo test message");
}
Example #15
0
void Player::hit() {
    if (getSprite() == NULL) {
        return;
    }
	CCSize size = CCDirector::sharedDirector()->getWinSize();
    Config::isPause = true;
	CCRenderTexture* renderTexture = CCRenderTexture::create(size.width, size.height);
	CCScene* temp = CCDirector::sharedDirector()->getRunningScene();
	renderTexture->begin(); 
	temp->visit();
	renderTexture->end();
	CCDirector::sharedDirector()->pushScene(GamePause::scene(renderTexture));
//	if (m_scene != NULL) {
//		Config::score++;
//		m_scene->setScore();
//	}
}
Example #16
0
void WallSingleScene::screenshot(CCObject* pSender){
	CCLog("screenshot");
	CCSize size = CCDirector::sharedDirector()->getWinSize();
	CCRenderTexture* texture = CCRenderTexture::create(size.width,size.height);
	texture->setPosition(ccp(size.width/2, size.height/2));
	texture->begin();
	CCDirector::sharedDirector()->getRunningScene()->visit();
	texture->end();
	texture->saveToFile("screenshot.png", kCCImageFormatPNG);
	DataTool::copyFileToSD("screenshot.png");
	MyToast::showToast(this,DataTool::getChinese("save_to_sd"),TOAST_LONG);

#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
	string path = CCFileUtils::sharedFileUtils()->getWritablePath();
	
#endif
}
Example #17
0
bool GameUtil::saveToFileFromSprite(CCSprite* pOrg, char* szFile)
{
	CCPoint ptOrg(pOrg->getPosition());

	CCRenderTexture * rt = CCRenderTexture::create((int)pOrg->getContentSize().width, (int)pOrg->getContentSize().height);
 
	pOrg->setPosition(ccp(pOrg->getContentSize().width/2, pOrg->getContentSize().height/2));
 
    rt->begin();
    pOrg->visit();
    rt->end();
	
	pOrg->setPosition(ptOrg);

	bool bSave = rt->saveToFile(szFile);

	return bSave;
}
Example #18
0
void ConfigMenu::screenshot()
{
	std::string sdcard = getSDCard();
	CCSize size = CCDirector::sharedDirector()->getWinSize();

	const char* imgName = "/bug_screenshot.jpg";
	sdcard = sdcard.append(imgName);
	CCRenderTexture* pScreen = CCRenderTexture::create(size.width, size.height);
	CCScene* pTempScene = CCDirector::sharedDirector()->getRunningScene();
	pScreen->begin();
	//pTempScene->visit();
	pTempScene->getChildByTag(TAG_RUNNING_LAYER)->visit();
	pScreen->end();
	pScreen->saveToFile(sdcard.c_str());
	CC_SAFE_DELETE(pScreen);
	share();
	CCLOG("sdcard %s", sdcard.c_str());
}
Example #19
0
CCRenderTexture* FightScene::createStroke(CCSprite* label, int size, ccColor3B color, GLubyte opacity)
{
    CCRenderTexture* rt = CCRenderTexture::create(
        label->getTexture()->getContentSize().width + size * 2,
        label->getTexture()->getContentSize().height+size * 2
        );

    CCPoint originalPos = label->getPosition();
    ccColor3B originalColor = label->getColor();
    GLubyte originalOpacity = label->getOpacity();
    bool originalVisibility = label->isVisible();
    label->setColor(color);
    label->setOpacity(opacity);
    label->setVisible(true);
    ccBlendFunc originalBlend = label->getBlendFunc();
    ccBlendFunc bf = {GL_SRC_ALPHA, GL_ONE};
    label->setBlendFunc(bf);
    CCPoint bottomLeft = ccp(
        label->getTexture()->getContentSize().width * label->getAnchorPoint().x + size, 
        label->getTexture()->getContentSize().height * label->getAnchorPoint().y + size);
    CCPoint positionOffset= ccp(
        - label->getTexture()->getContentSize().width / 2,
        - label->getTexture()->getContentSize().height / 2);
    CCPoint position = ccpSub(originalPos, positionOffset);
    rt->begin();
    for (int i=0; i<360; i+= 15) // you should optimize that for your needs
    {
        label->setPosition(
            ccp(bottomLeft.x + sin(CC_DEGREES_TO_RADIANS(i))*size, bottomLeft.y + cos(CC_DEGREES_TO_RADIANS(i))*size)
            );
        label->visit();
    }
    rt->end();

    label->setPosition(originalPos);
    label->setColor(originalColor);
    label->setBlendFunc(originalBlend);
	label->setVisible(originalVisibility);
    label->setOpacity(originalOpacity);
    rt->setPosition(position);

    return rt;
}
/**
 * 截图功能
 */
void HelloWorld::saveScreenshot() {
    CCSize size = CCDirector::sharedDirector()->getWinSize();
    CCRenderTexture* texture = CCRenderTexture::create((int) size.width,
                               (int) size.height);
    texture->setPosition(ccp(size.width / 2, size.height / 2));
    texture->begin();
    CCDirector::sharedDirector()->getRunningScene()->visit();
    texture->end();
    string imagePath =
        CCFileUtils::sharedFileUtils()->getWritablePath().c_str();
    CCLog(imagePath.c_str());
    //保存为png
    bool result = texture->saveToFile("screenshot.png", kCCImageFormatPNG);
    if (result) {
        imagePath += "screenshot.png";
        CCLog(imagePath.c_str());
    }

}
// CCTransitionProgress
void CCTransitionProgress::onEnter()
{
    CCTransitionScene::onEnter();

    setupTransition();
    
    // create a transparent color layer
    // in which we are going to add our rendertextures
    CCSize size = CCDirector::sharedDirector()->getWinSize();

    // create the second render texture for outScene
    CCRenderTexture *texture = CCRenderTexture::renderTextureWithWidthAndHeight((int)size.width, (int)size.height);
    texture->getSprite()->setAnchorPoint(ccp(0.5f,0.5f));
    texture->setPosition(ccp(size.width/2, size.height/2));
    texture->setAnchorPoint(ccp(0.5f,0.5f));

    // render outScene to its texturebuffer
    texture->clear(0, 0, 0, 1);
    texture->begin();
    m_pSceneToBeModified->visit();
    texture->end();


    //    Since we've passed the outScene to the texture we don't need it.
    if (m_pSceneToBeModified == m_pOutScene)
    {
        hideOutShowIn();
    }
    //    We need the texture in RenderTexture.
    CCProgressTimer *pNode = progressTimerNodeWithRenderTexture(texture);

    // create the blend action
    CCActionInterval* layerAction = (CCActionInterval*)CCSequence::create(
        CCProgressFromTo::create(m_fDuration, m_fFrom, m_fTo),
        CCCallFunc::create(this, callfunc_selector(CCTransitionProgress::finish)), 
        NULL);
    // run the blend action
    pNode->runAction(layerAction);

    // add the layer (which contains our two rendertextures) to the scene
    addChild(pNode, 2, kCCSceneRadial);
}
Example #22
0
	void TilemapRender::generateBackground()
	{
		ostringstream texturePath;
		texturePath<<"resources.pak/terrain/";
		texturePath<<m_SetID<<"-14.png";
		
		CCRenderTexture* rt = CCRenderTexture::create(64,64);
		rt->begin();
		CCSprite* tile1 = CCSprite::create(texturePath.str().c_str());
		tile1->setAnchorPoint(ccp(0,0));
		tile1->setPosition(ccp(0,0));
		tile1->visit();
		rt->end();

		CCTexture2D* texture = rt->getSprite()->getTexture();
		ccTexParams tp = {GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT};
		texture->setTexParameters(&tp);
		m_SpriteB->setTexture(texture);
		m_SpriteB->setTextureRect(CCRectMake(0, 0, m_MapWidth*64, m_MapHeight*64));
	}
KDvoid RenderTextureZbuffer::renderScreenShot ( KDvoid )
{
	CCRenderTexture*  pTexture = CCRenderTexture::create ( 512, 512 );
	pTexture->setAnchorPoint ( ccp ( 0, 0 ) );

	pTexture->begin ( );

	this->visit ( );

	pTexture->end ( );

	CCSprite*  pSprite = CCSprite::createWithTexture ( pTexture->getSprite ( )->getTexture ( ) );

	pSprite->setPosition ( ccp ( 256, 256 ) );
	pSprite->setOpacity ( 182 );
	pSprite->setFlipY ( 1 );
	pSprite->setColor ( ccGREEN );
	pSprite->runAction ( CCSequence::create ( CCFadeTo::create ( 2, 0 ), CCHide::create ( ), KD_NULL ) );

	this->addChild ( pSprite, 999999 );			
}
void CCControlSwitchSprite::needsLayout()
{
    m_pOnSprite->setPosition(ccp(m_pOnSprite->getContentSize().width / 2 + m_fSliderXPosition,
                                 m_pOnSprite->getContentSize().height / 2));
    m_pOffSprite->setPosition(ccp(m_pOnSprite->getContentSize().width + m_pOffSprite->getContentSize().width / 2 + m_fSliderXPosition,
                                  m_pOffSprite->getContentSize().height / 2));
    m_ThumbSprite->setPosition(ccp(m_pOnSprite->getContentSize().width + m_fSliderXPosition,
                                   m_pMaskTexture->getContentSize().height / 2));

    if (m_pOnLabel)
    {
        m_pOnLabel->setPosition(ccp(m_pOnSprite->getPosition().x - m_ThumbSprite->getContentSize().width / 6,
                                    m_pOnSprite->getContentSize().height / 2));
    }
    if (m_pOffLabel)
    {
        m_pOffLabel->setPosition(ccp(m_pOffSprite->getPosition().x + m_ThumbSprite->getContentSize().width / 6,
                                     m_pOffSprite->getContentSize().height / 2));
    }

    CCRenderTexture *rt = CCRenderTexture::create((int)m_pMaskTexture->getContentSize().width, (int)m_pMaskTexture->getContentSize().height);

    rt->begin();
    m_pOnSprite->visit();
    m_pOffSprite->visit();

    if (m_pOnLabel)
    {
        m_pOnLabel->visit();
    }
    if (m_pOffLabel)
    {
        m_pOffLabel->visit();
    }

    rt->end();

    setTexture(rt->getSprite()->getTexture());
    setFlipY(true);
}
Example #25
0
bool GameUtil::maskedSpriteToFile(CCSprite* textureSprite, CCSprite* maskSprite, char* szFile)
{
	// store the original positions of both sprites
	CCPoint ptOrgT(textureSprite->getPosition());
	CCPoint ptOrgM(maskSprite->getPosition());

	// 1. Create a CCRenderTexture with the same width/height as the mask sprite.
	CCRenderTexture * rt = CCRenderTexture::create((int)maskSprite->getContentSize().width, (int)maskSprite->getContentSize().height);
 
    // 2. Positions the mask sprite and texture sprite so their bottom left is at 0,0.
	maskSprite->setPosition(ccp(maskSprite->getContentSize().width/2, maskSprite->getContentSize().height/2));
	textureSprite->setPosition(ccp(textureSprite->getContentSize().width/2, textureSprite->getContentSize().height/2));
 
    // 3. Sets up the blend functions for each sprite as discussed earlier.
    ccBlendFunc bfMask = ccBlendFunc();
    bfMask.src = GL_ONE;
    bfMask.dst = GL_ZERO;
    maskSprite->setBlendFunc(bfMask);

	ccBlendFunc bfTexture = ccBlendFunc();
	bfTexture.src = GL_DST_ALPHA;
	bfTexture.dst = GL_ZERO;
	textureSprite->setBlendFunc(bfTexture);
 
    // 4. Calls begin to start drawing into the CCRenderTexture, draws the mask and then the texture, 
	// and then calls end to finalize drawing.
    rt->begin();
    maskSprite->visit();
    textureSprite->visit();
    rt->end();
	
	// restore the original sprite positions
	textureSprite->setPosition(ptOrgT);
	maskSprite->setPosition(ptOrgM);

	bool bRet = rt->saveToFile(szFile);

	return bRet;
}
Example #26
0
CCTexture2D* Util::getGrayTexture(CCTexture2D* texture){
		typedef enum {  
			RED = 0,  
			GREEN = 1,  
			BLUE = 2,  
			ALPHA = 3  
		} PIXELS;  
		CCSize textSize = texture->getContentSize();
		CCSprite *temporarySprite = CCSprite::createWithTexture(texture);
		//就这么一小句搞了我半天了,不过能出来也值了
		temporarySprite->setAnchorPoint(ccp(0,0));
		CCRenderTexture *rt = CCRenderTexture::create(textSize.width, textSize.height);
		rt->begin();
		temporarySprite->visit();
		rt->end();
		
		CCImage *image = rt->newCCImage();
		unsigned char* pixels = image->getData();
		int len = image->getDataLen();
		uint32_t *p = (uint32_t *)pixels;
		for(int i=0;i<len;i++){
			uint8_t *rgbaPixel = (uint8_t *) &p[i];
			//uint32_t gray = 0.3 * rgbaPixel[RED] + 0.59 * rgbaPixel[GREEN] + 0.11 * rgbaPixel[BLUE];
			uint32_t gray = 1.2*rgbaPixel[RED] + 1.0*rgbaPixel[GREEN] + 0.0*rgbaPixel[BLUE];
			// set the pixels to gray  
			rgbaPixel[RED] = gray;  
			rgbaPixel[GREEN] = gray;  
			rgbaPixel[BLUE] = gray;  
		}
		CCTexture2D* newtexture = new CCTexture2D();  
		newtexture->autorelease();
		newtexture->initWithImage(image);

		image->release();
		return newtexture;
}
Example #27
0
void CCTransitionCrossFade::onEnter()
{
    CCTransitionScene::onEnter();

    // create a transparent color layer
    // in which we are going to add our rendertextures
    ccColor4B  color = {0,0,0,0};
    CCSize size = CCDirector::sharedDirector()->getWinSize();
    CCLayerColor* layer = CCLayerColor::create(color);

    // create the first render texture for inScene
    CCRenderTexture* inTexture = CCRenderTexture::create((int)size.width, (int)size.height);

    if (NULL == inTexture)
    {
        return;
    }

    inTexture->getSprite()->setAnchorPoint( ccp(0.5f,0.5f) );
    inTexture->setPosition( ccp(size.width/2, size.height/2) );
    inTexture->setAnchorPoint( ccp(0.5f,0.5f) );

    // render inScene to its texturebuffer
    inTexture->begin();
    m_pInScene->visit();
    inTexture->end();

    // create the second render texture for outScene
    CCRenderTexture* outTexture = CCRenderTexture::create((int)size.width, (int)size.height);
    outTexture->getSprite()->setAnchorPoint( ccp(0.5f,0.5f) );
    outTexture->setPosition( ccp(size.width/2, size.height/2) );
    outTexture->setAnchorPoint( ccp(0.5f,0.5f) );

    // render outScene to its texturebuffer
    outTexture->begin();
    m_pOutScene->visit();
    outTexture->end();

    // create blend functions

    ccBlendFunc blend1 = {GL_ONE, GL_ONE}; // inScene will lay on background and will not be used with alpha
    ccBlendFunc blend2 = {GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA}; // we are going to blend outScene via alpha 

    // set blendfunctions
    inTexture->getSprite()->setBlendFunc(blend1);
    outTexture->getSprite()->setBlendFunc(blend2);    

    // add render textures to the layer
    layer->addChild(inTexture);
    layer->addChild(outTexture);

    // initial opacity:
    inTexture->getSprite()->setOpacity(255);
    outTexture->getSprite()->setOpacity(255);

    // create the blend action
    CCAction* layerAction = CCSequence::create
    (
        CCFadeTo::create(m_fDuration, 0),
        CCCallFunc::create(this, callfunc_selector(CCTransitionScene::hideOutShowIn)),
        CCCallFunc::create(this, callfunc_selector(CCTransitionScene::finish)),
        NULL
    );


    // run the blend action
    outTexture->getSprite()->runAction( layerAction );

    // add the layer (which contains our two rendertextures) to the scene
    addChild(layer, 2, kSceneFade);
}
Example #28
0
bool CCTubeGridTile::initWithType(int type, bool backGround,TileColor color)
{
    CCRenderTexture* pRt = CCRenderTexture::create(tileWidth,tileHeight);
	if (backGround)
	{
		pRt->begin();
        
		float flineWidth = 0.3;
		ccDrawSolidRect(ccp(flineWidth,flineWidth),ccp(tileWidth-flineWidth, tileHeight-flineWidth),tileBackgroundColor);
        
		pRt->end();
	}
    
	if(!initWithTexture(pRt->getSprite()->getTexture()))return false;
	
    
	//do image initialization with type
    CCPoint childPosWithOffset = ccp(tileWidth/2, tileHeight/2);
    ChildTubeSprite* podChild1 = NULL;
    ChildTubeSprite* podChild2 = NULL;
    
    this->type = type;
	m_canGetFireLocation = false;
	if (TILETYPE_LINE_ONE_HORIZONTAL == type||
		TILETYPE_LINE_ONE_VERTICAL == type||
		TILETYPE_LINE_TWO_HORIZONTALONTOP == type||
		TILETYPE_LINE_TWO_VERTICALONTOP == type)
	{
		genericType = GENERIC_TYPE_LINE;
        initLine1(color);
        if (TILETYPE_LINE_TWO_HORIZONTALONTOP == type||
            TILETYPE_LINE_TWO_VERTICALONTOP == type) {
            initLine2(color);
        }
	}
	else
	{
		genericType = GENERIC_TYPE_CURVE;
        initCurve1(color);
        if (TILETYPE_CURVE_TWO_BOTTONLEFT_TOPRIGHT == type||
            TILETYPE_CURVE_TWO_TOPLEFT_BOTTONRIGHT == type) {
            initCurve2(color);
        }
	}
    
	switch (type)
	{
        case TILETYPE_VOID:
		{
            //create the void tile render texture
            m_rtVoid = CCRenderTexture::create(tileWidth,tileHeight);
            m_rtVoid->begin();
            ccColor4F colorVoid = {0,0,0
                ,1.0f};
            ccDrawSolidRect(ccp(0,0),ccp(tileWidth, tileHeight),colorVoid);
            m_rtVoid->end();
			setTexture(m_rtVoid->getSprite()->getTexture());
			break;
		}
        case TILETYPE_NOTUBE:
		{
			break;
		}
        case TILETYPE_CURVE_ONE_BOTTONLEFT:
		{
            
            podChild1 = ChildTubeSprite::createWithTexture(m_rtCurve->getSprite()->getTexture());
			podChild1->setPosition(childPosWithOffset);
			podChild1->setRotation(-90);
			podChild1->setTag(TAG_CURVE_BOTTONLEFT);
			addChild(podChild1,Z_CHILD1);
			break;
		}
        case TILETYPE_CURVE_ONE_BOTTONRIGHT:
		{
            podChild1 = ChildTubeSprite::createWithTexture(m_rtCurve->getSprite()->getTexture());
			podChild1->setPosition(childPosWithOffset);
			podChild1->setRotation(-180);
			podChild1->setTag(TAG_CURVE_BOTTONRIGHT);
			addChild(podChild1,Z_CHILD1);
			break;
		}
        case TILETYPE_CURVE_ONE_TOPLEFT:
		{
			podChild1 = ChildTubeSprite::createWithTexture(m_rtCurve->getSprite()->getTexture());
			podChild1->setPosition(childPosWithOffset);
			podChild1->setTag(TAG_CURVE_TOPLEFT);
			addChild(podChild1,Z_CHILD1);
			break;
		}
        case TILETYPE_CURVE_ONE_TOPRIGHT:
		{
			podChild1 = ChildTubeSprite::createWithTexture(m_rtCurve->getSprite()->getTexture());
			podChild1->setPosition(childPosWithOffset);
			podChild1->setRotation(90);
			podChild1->setTag(TAG_CURVE_TOPRIGHT);
			addChild(podChild1,Z_CHILD1);
			break;
		}
        case TILETYPE_CURVE_TWO_TOPLEFT_BOTTONRIGHT:
		{
			podChild1 = ChildTubeSprite::createWithTexture(m_rtCurve->getSprite()->getTexture());
			podChild1->setPosition(childPosWithOffset);
            
			podChild1->setTag(TAG_CURVE_TOPLEFT);
            addChild(podChild1,Z_CHILD1);
            
			podChild2 = ChildTubeSprite::createWithTexture(m_rtCurve2->getSprite()->getTexture());
			podChild2->setPosition(childPosWithOffset);
			podChild2->setRotation(180);
			podChild2->setTag(TAG_CURVE_BOTTONRIGHT);
			addChild(podChild2,Z_CHILD2);
            
			break;
		}
        case TILETYPE_CURVE_TWO_BOTTONLEFT_TOPRIGHT:
		{
			podChild1 = ChildTubeSprite::createWithTexture(m_rtCurve->getSprite()->getTexture());
			podChild1->setPosition(childPosWithOffset);
			podChild1->setRotation(-90);
			podChild1->setTag(TAG_CURVE_BOTTONLEFT);
			addChild(podChild1,Z_CHILD1);
            
			podChild2 = ChildTubeSprite::createWithTexture(m_rtCurve2->getSprite()->getTexture());
			podChild2->setPosition(childPosWithOffset);
			podChild2->setRotation(90);
			podChild2->setTag(TAG_CURVE_TOPRIGHT);
            
			addChild(podChild2,Z_CHILD2);
            
			break;
		}
        case TILETYPE_LINE_ONE_HORIZONTAL:
		{
			podChild1 = ChildTubeSprite::createWithTexture(m_rtLine->getSprite()->getTexture());
			podChild1->setPosition(childPosWithOffset);
			podChild1->setRotation(-90);
			podChild1->setTag(TAG_LINE_HORIZONTAL);
			addChild(podChild1,Z_CHILD1);
			break;
		}
        case TILETYPE_LINE_ONE_VERTICAL:
		{
			podChild1 = ChildTubeSprite::createWithTexture(m_rtLine->getSprite()->getTexture());
			podChild1->setPosition(childPosWithOffset);
			podChild1->setTag(TAG_LINE_VERTICAL);
			addChild(podChild1,Z_CHILD1);
			break;
		}
        case TILETYPE_LINE_TWO_HORIZONTALONTOP:
		{
			podChild1 = ChildTubeSprite::createWithTexture(m_rtLine->getSprite()->getTexture());
			podChild1->setPosition(childPosWithOffset);
			podChild1->setTag(TAG_LINE_VERTICAL);
			addChild(podChild1,Z_CHILD1);
            
			podChild2 = ChildTubeSprite::createWithTexture(m_rtLine2->getSprite()->getTexture());
			podChild2->setPosition(childPosWithOffset);
			podChild2->setRotation(-90);
			podChild2->setTag(TAG_LINE_HORIZONTAL);
			addChild(podChild2,Z_CHILD2);
			break;
		}
        case TILETYPE_LINE_TWO_VERTICALONTOP:
		{
			podChild1 = ChildTubeSprite::createWithTexture(m_rtLine->getSprite()->getTexture());
			podChild1->setPosition(childPosWithOffset);
			podChild1->setRotation(-90);
			podChild1->setTag(TAG_LINE_HORIZONTAL);
			addChild(podChild1,Z_CHILD1);
            
			podChild2 = ChildTubeSprite::createWithTexture(m_rtLine2->getSprite()->getTexture());
			podChild2->setPosition(ccp(tileWidth/2,tileHeight/2));
			podChild2->setTag(TAG_LINE_VERTICAL);
			addChild(podChild2,Z_CHILD2);
			break;
		}
        default:
            break;
	}
    
    //////solve the not match glitch
    if (podChild1) {
        podChild1->setScale(tile_rt_scale);
    }
    if (podChild2) {
        podChild2->setScale(tile_rt_scale);
    }
    ///////////////////////
    
	
    
    //set the render texture
    if (genericType == GENERIC_TYPE_LINE) {
        if (podChild1) {
            podChild1->setRenderTexture(m_rtLine);
        }
        if (podChild2) {
            podChild2->setRenderTexture(m_rtLine2);
        }
    }
    else
    {
        if (podChild1) {
            podChild1->setRenderTexture(m_rtCurve);
        }
        if (podChild2) {
            podChild2->setRenderTexture(m_rtCurve2);
        }
    }
    
	//decide tubeCount
	if (TILETYPE_VOID == type||TILETYPE_NOTUBE == type)
	{
		m_remainTubes = 0;
	}
	else if (TILETYPE_LINE_TWO_VERTICALONTOP == type ||TILETYPE_LINE_TWO_HORIZONTALONTOP == type ||
             TILETYPE_CURVE_TWO_BOTTONLEFT_TOPRIGHT == type ||TILETYPE_CURVE_TWO_TOPLEFT_BOTTONRIGHT == type )
	{
		m_remainTubes = 2;
	}
	else
	{
		m_remainTubes = 1;
	}
    return true;
}
Example #29
0
CCSprite * BSAddStrokeToLabel(cocos2d::CCLabelTTF * label, float size, cocos2d::ccColor3B color, GLubyte opacity) {
    CCPoint originalPos = label->getPosition();
    ccColor3B originalColor = label->getColor();
    GLubyte originalOpacity = label->getOpacity();
    bool originalVisibility = label->isVisible();
    ccBlendFunc originalBlend = label->getBlendFunc();
    
    label->setColor(color);
    label->setOpacity(opacity);
    ccBlendFunc bf = {GL_SRC_ALPHA, GL_ONE};
    label->setBlendFunc(bf);
    
    CCPoint bottomLeft = ccp(label->getTexture()->getContentSize().width * label->getAnchorPoint().x + size,
                             label->getTexture()->getContentSize().height * label->getAnchorPoint().y + size);
    CCRenderTexture* rt = CCRenderTexture::create(label->getTexture()->getContentSize().width + size * 2,
                                                  label->getTexture()->getContentSize().height + size * 2);
    /* 在原始位置绘制文字,用于镂空用 */
    label->setPosition(bottomLeft);
    rt->begin();
    label->visit();
    rt->end();
    CCImage * originText = rt->newCCImage();
    glBlendEquation(GL_BLEND_EQUATION_ALPHA);
    /* 在各个方向上移动文字,重叠得到未镂空的描边 */
    rt->begin();
    /* Bresenham's circle algorithm */
    int radis = 3 * size;
    for (int x = 0, y = radis, d = 3 - 2 * radis; x <= y; ++x) {
        float xx = x / 3.0F, yy = y / 3.0F;
        label->setPosition(ccp(bottomLeft.x + xx, bottomLeft.y + yy)); label->visit();
        label->setPosition(ccp(bottomLeft.x - xx, bottomLeft.y + yy)); label->visit();
        label->setPosition(ccp(bottomLeft.x + xx, bottomLeft.y - yy)); label->visit();
        label->setPosition(ccp(bottomLeft.x - xx, bottomLeft.y - yy)); label->visit();
        label->setPosition(ccp(bottomLeft.x + yy, bottomLeft.y + xx)); label->visit();
        label->setPosition(ccp(bottomLeft.x - yy, bottomLeft.y + xx)); label->visit();
        label->setPosition(ccp(bottomLeft.x + yy, bottomLeft.y - xx)); label->visit();
        label->setPosition(ccp(bottomLeft.x - yy, bottomLeft.y - xx)); label->visit();
        if (d < 0) {
            d = d + 4 * x + 6;
        } else {
            d = d + 4 * (x - y) + 10;
            y --;
        }
    }
    rt->end();
    
    /* TODO: ugly workaround. rendertexture多次绘制颜色叠加,需要取色值大的那个,需要通过glBlendEquation(GL_MAX)实现。
     * see http://stackoverflow.com/questions/2143690/is-it-possible-to-achieve-maxas-ad-opengl-blending */
    CCImage * strokedText = rt->newCCImage();
    unsigned char * pStorke = strokedText->getData();
    unsigned char * pErase = originText->getData();
    for (int i = 0; i < strokedText->getDataLen(); ++i) {
        if ((unsigned int) pErase[i * 4] != 0) {
            *(unsigned int *) &pStorke[i * 4] = 0;
        } else if ((unsigned int) pStorke[i * 4] != 0) {
            unsigned char * pixel = &pStorke[i * 4];
            (*pixel++) = color.r;
            (*pixel++) = color.g;
            (*pixel++) = color.b;
             *pixel    = opacity;
        }
    }
    originText->release();
    
    /* 用RenderTexture构造一个Sprite,以实现支持透明度 FadeIn FadeOut */
    CCTexture2D * texture2D = new CCTexture2D();
    texture2D->initWithImage(strokedText);
    strokedText->release();
    CCSprite * sprite = CCSprite::createWithTexture(texture2D);
    texture2D->release();
    
    label->setPosition(originalPos);
    label->setColor(originalColor);
    label->setBlendFunc(originalBlend);
    label->setVisible(originalVisibility);
    label->setOpacity(originalOpacity);
    
    sprite->setPosition(ccp(label->getTexture()->getContentSize().width / 2, label->getTexture()->getContentSize().height / 2));
    label->addChild(sprite, -1);
    
    return sprite;
}
Example #30
0
int Bitmap::handler_method_drawtext( int ptr1,void* ptr2 )
{
 	Bitmap* bitmap = (Bitmap*)ptr1;
	if (NULL==bitmap->p->m_emuBitmap)
		return -1;

	bool firstdraw = false;
	CCRenderTexture* fontRender = (CCRenderTexture*)bitmap->p->m_fontRender;
	if (NULL==fontRender)
	{
		fontRender = CCRenderTexture::create(bitmap->p->m_width,bitmap->p->m_height);
		bitmap->getEmuBitmap()->addChild(fontRender);
		fontRender->setPosition(ccp(bitmap->p->m_width/2,bitmap->p->m_height/2));
		bitmap->p->m_fontRender = fontRender;
		fontRender->retain();
		firstdraw = true;
		//fontRender->getSprite()->getTexture()->setAliasTexParameters();
	}

	DrawtextStruct* ptr2struct = (DrawtextStruct*)ptr2;
	string tmpdrawchar = ptr2struct->str;
// 	int checknum = atoi(tmpdrawchar.c_str());
// 	if (checknum!=0)
// 	{
// 		char tmp[20]={0};
// 		sprintf(tmp,"%d",checknum);
// 		tmpdrawchar = tmp;
// 	}

	CCLabelTTF* label = CCLabelTTF::create(tmpdrawchar.c_str(),ptr2struct->font->getName(),ptr2struct->font->getSize());
	//label->getTexture()->setAliasTexParameters();
	if (ptr2struct->font)
	{
		Font* f = ptr2struct->font; 
		label->setFontName(f->getName());
		label->setFontSize(f->getSize());
		label->setColor(ccc3(f->getColor()->red*f->getColor()->alpha/255,
			f->getColor()->green*f->getColor()->alpha/255,
			f->getColor()->blue*f->getColor()->alpha/255));
		//label->setOpacity(f->getColor()->alpha);
	}
	label->setAnchorPoint(ccp(0,1));
	label->setDimensions(CCSizeMake(ptr2struct->rect.w,ptr2struct->rect.h));
	label->setPosition(ccp(ptr2struct->rect.x,rgss_y_to_cocos_y(ptr2struct->rect.y,bitmap->p->m_height)));
	label->setVerticalAlignment(kCCVerticalTextAlignmentCenter);

	if (ptr2struct->align == Bitmap::Center)
		label->setHorizontalAlignment(kCCTextAlignmentCenter);
	else if(ptr2struct->align == Bitmap::Right)
		label->setHorizontalAlignment(kCCTextAlignmentRight);
	else if (ptr2struct->align == Bitmap::Left)
		label->setHorizontalAlignment(kCCTextAlignmentLeft);

// 	CCLayerColor* masklayer = CCLayerColor::create(ccc4(255,255,255,255));
// 	masklayer->setContentSize(label->getContentSize());
// 	masklayer->setPosition(ccp(ptr2struct->rect.x,rgss_y_to_cocos_y(ptr2struct->rect.y,bitmap->m_height)-masklayer->getContentSize().height));
// 	ccBlendFunc fun = {GL_ZERO,GL_ZERO};
// 	masklayer->setBlendFunc(fun);

	fontRender->begin();
	//masklayer->visit();
	label->visit();
	fontRender->end();
	label->release();

	delete ptr2struct;
	return 0;
}