//--------------------------------------------------------
ccColor4F CRenderTextureLayer::RandomOneBrightColor()
{
	while (true)
	{
		float requiredBrightness = 192;
		ccColor4B randomColor = ccc4(rand() % 255, rand() % 255, rand() % 255, 255);
		if (randomColor.r > requiredBrightness || 
			randomColor.g > requiredBrightness ||
			randomColor.b > requiredBrightness)
		{
			return ccc4FFromccc4B(randomColor);
		}
	}
}
    virtual bool init()
    {
        if ( CCNode::init() == false ) {
            return false;
        }
        
        objSize_    = CCSizeMake(120, 120);

        CCDrawNode* pTestDraw   = CCDrawNode::create();
        pTestDraw->drawDot(ccp(0,0), objSize_.width * 0.5f, ccc4FFromccc4B(ccc4(128, 0, 0, 230)));
        
        addChild(pTestDraw);
        
        return true;
    }
Exemple #3
0
    virtual bool init()
    {
        if ( CCNode::init() == false ) {
            return false;
        }
        
        objSize_    = CCSizeMake(60, 60);

        //  テスト描画用
        {
            CCDrawNode* pTestDraw  = CCDrawNode::create();
            pTestDraw->drawDot(ccp(0,0), objSize_.width * 0.5f, ccc4FFromccc4B(ccc4(255, 255, 255, 128)));
            addChild(pTestDraw);
        }

        return true;
    }
ccColor4F HelloWorld::randomBrightColor()
{
    while (true)
    {
        float requiredBrightness = 192;
        ccColor4B randomColor = ccc4(rand() % 255,
                                     rand() % 255,
                                     rand() % 255,
                                     255);

        if (randomColor.r > requiredBrightness ||
                randomColor.g > requiredBrightness ||
                randomColor.b > requiredBrightness)
        {
            return ccc4FFromccc4B(randomColor);
        }

    }
}
void HelloWorld::ChangeParticle(float scale, bool isBackgroundMove, int backgroundMoveSpeed, float angle, float angleVar, int destBlendFunc, int srcBlendFunc, float duration, float emissionRate, int emiiterMode,
	GLbyte endColorR,GLbyte endColorG,GLbyte endColorB,GLbyte endColorA,
	GLbyte endColorVarR,GLbyte endColorVarG,GLbyte endColorVarB,GLbyte endColorVarA,
	float endRadius,float endRadiusVar,
	float endSize,float endSizeVar,
	float endSpin,float endSpinVar,
	float gravityX,float gravityY,
	bool isAutoRemoveOnFinish,
	float life,float lifeVar,
	int positionType,
	float positionVarX,float positionVarY,
	float radialAccel,float radialAccelVar,
	float rotatePerSecond,float rotatePerSecondVar,
	float sourcePositionX,float sourcePositionY,
	float speed,float speedVar,
	GLbyte startColorR,GLbyte startColorG,GLbyte startColorB,GLbyte startColorA,
	GLbyte startColorVarR,GLbyte startColorVarG,GLbyte startColorVarB,GLbyte startColorVarA,
	float startRadius,float startRadiusVar,
	float startSize,float startSizeVar,
	float startSpin,float startSpinVar,
	float tangentialAccel,float tangentialAccelVar,
	char* plistPath,char* texturePath,char* textureImageData,
	unsigned int totalParticles
	)
{

	if (texturePath==NULL||strlen(texturePath)==0)
	{
		return;
	}

	//mBackground->setScale(scale);

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

	if (totalParticles!=mEmiiter->getTotalParticles())
	{
		mEmiiter->removeFromParentAndCleanup(true);

		mEmiiter=new CCParticleSystemQuad();

		mEmiiter->initWithTotalParticles(totalParticles);
		mEmiiter->setPosition(ccp(size.width/2,size.height/2));

		mEmiiter->setTexture(CCTextureCache::sharedTextureCache()->addImage("fire.png"));

		mBackground->addChild(mEmiiter,1);
	}

	//if (isBackgroundMove!=mIsBackgroundMove)
	//{
		mIsBackgroundMove=isBackgroundMove;


		mBackground->stopAllActions();
		mBackground->setPosition(ccp(size.width/2,size.height/2));

		if (mIsBackgroundMove)
		{
			CCActionInterval* move1 = CCMoveBy::create(1.0 / backgroundMoveSpeed, CCPointMake(100,0) );
			CCActionInterval* move2 = CCMoveBy::create(1.0 / backgroundMoveSpeed, CCPointMake(0,100) );
			CCActionInterval* move3 = CCMoveBy::create(1.0 / backgroundMoveSpeed, CCPointMake(-100,0) );
			CCActionInterval* move4 = CCMoveBy::create(1.0 / backgroundMoveSpeed, CCPointMake(0,-100) );

			CCFiniteTimeAction* seq = CCSequence::create(move1, move2, move3,move4,NULL);
			mBackground->runAction( CCRepeatForever::create((CCActionInterval*)seq) );
		}
	//}

	CCTexture2D *tex = NULL;

	if (texturePath!=NULL)
	{
		// set not pop-up message box when load image failed
		bool bNotify = CCFileUtils::sharedFileUtils()->isPopupNotify();
		CCFileUtils::sharedFileUtils()->setPopupNotify(false);


		//tex = CCTextureCache::sharedTextureCache()->addImage(texturePath);
		if (tex==NULL)
		{
			std::string secondPath=plistPath;
			secondPath+="/";
			secondPath+=texturePath;
			tex = CCTextureCache::sharedTextureCache()->addImage(secondPath.c_str());
		}
		
		// reset the value of UIImage notify
		CCFileUtils::sharedFileUtils()->setPopupNotify(bNotify);
	}

	if (tex)
	{
		mEmiiter->setTexture(tex);
	}
	else
	{                        
		
		unsigned char *buffer = NULL;
		unsigned char *deflated = NULL;
		CCImage *image = NULL;

		CCAssert(textureImageData, "");

		int dataLen = strlen(textureImageData);
		if(dataLen != 0)
		{
			// if it fails, try to get it from the base64-gzipped data    
			int decodeLen = base64Decode((unsigned char*)textureImageData, (unsigned int)dataLen, &buffer);
			CCAssert( buffer != NULL, "CCParticleSystem: error decoding textureImageData");


			int deflatedLen = ZipUtils::ccInflateMemory(buffer, decodeLen, &deflated);
			CCAssert( deflated != NULL, "CCParticleSystem: error ungzipping textureImageData");

			// For android, we should retain it in VolatileTexture::addCCImage which invoked in CCTextureCache::sharedTextureCache()->addUIImage()
			image = new CCImage();
			bool isOK = image->initWithImageData(deflated, deflatedLen);
			CCAssert(isOK, "CCParticleSystem: error init image with Data");

			mEmiiter->setTexture(CCTextureCache::sharedTextureCache()->addUIImage(image, texturePath));

			image->release();
		}

		CC_SAFE_DELETE_ARRAY(buffer);
		CC_SAFE_DELETE_ARRAY(deflated);
	}

	mEmiiter->setAngle(angle);
	mEmiiter->setAngleVar(angleVar);


	ccBlendFunc func;
	func.dst=destBlendFunc;
	func.src=srcBlendFunc;
	mEmiiter->setBlendFunc(func);

	mEmiiter->setDuration(duration);
	mEmiiter->setEmissionRate(emissionRate);
	mEmiiter->setEmitterMode(emiiterMode);

	ccColor4F endColor=ccc4FFromccc4B(ccc4(endColorR,endColorG,endColorB,endColorA));
	mEmiiter->setEndColor(endColor);

	ccColor4F endColorVar=ccc4FFromccc4B(ccc4(endColorVarR,endColorVarG,endColorVarB,endColorVarA));
	mEmiiter->setEndColorVar(endColorVar);

	if (emiiterMode==kCCParticleModeGravity )
	{
		mEmiiter->setGravity(ccp(gravityX,gravityY));
		mEmiiter->setSpeed(speed);
		mEmiiter->setSpeedVar(speedVar);

		mEmiiter->setTangentialAccel(tangentialAccel);
		mEmiiter->setTangentialAccelVar(tangentialAccelVar);

		mEmiiter->setRadialAccel(radialAccel);
		mEmiiter->setRadialAccelVar(radialAccelVar);

	}
	else if (emiiterMode==kCCParticleModeRadius)
	{
		mEmiiter->setStartRadius(startRadius);
		mEmiiter->setStartRadiusVar(startRadiusVar);

		mEmiiter->setEndRadius(endRadius);
		mEmiiter->setEndRadiusVar(endRadiusVar);

		mEmiiter->setRotatePerSecond(rotatePerSecond);
		mEmiiter->setRotatePerSecondVar(rotatePerSecondVar);
	}



	mEmiiter->setEndSize(endSize);
	mEmiiter->setEndSizeVar(endSizeVar);

	mEmiiter->setEndSpin(endSpin);
	mEmiiter->setEndSpinVar(endSpinVar);

	mEmiiter->setAutoRemoveOnFinish(isAutoRemoveOnFinish);

	mEmiiter->setLife(life);
	mEmiiter->setLifeVar(lifeVar);
	mEmiiter->setPositionType((tCCPositionType)positionType);
	mEmiiter->setPosVar(ccp(positionVarX,positionVarY));

	mEmiiter->setSourcePosition(ccp(sourcePositionX,sourcePositionY));

	ccColor4F startColor=ccc4FFromccc4B(ccc4(startColorR,startColorG,startColorB,startColorA));
	mEmiiter->setStartColor(startColor);

	ccColor4F startColorVar=ccc4FFromccc4B(ccc4(startColorVarR,startColorVarG,startColorVarB,startColorVarA));
	mEmiiter->setStartColorVar(startColorVar);

	mEmiiter->setStartSize(startSize);
	mEmiiter->setStartSizeVar(startSizeVar);

	
	mEmiiter->setTotalParticles(totalParticles);

	mEmiiter->resetSystem();

	CCEGLView* eglView = CCEGLView::sharedOpenGLView();

	eglView->setFrameZoomFactor(1.f * scale);
}
void ccDrawSolidRoundRect(CCPoint origin, CCPoint destination, float cornerRadius, ccColor4B color) {
    // ensure origin is left bottom
    CCPoint bl = origin;
    CCPoint tr = destination;
    if(bl.x > tr.x) {
        bl.x = MIN(origin.x, destination.x);
        tr.x = MAX(origin.x, destination.x);
    }
    if(bl.y > tr.y) {
        bl.y = MIN(origin.y, destination.y);
        tr.y = MAX(origin.y, destination.y);
    }
    
    // four center of corners
    CCPoint tlCenter = ccp(bl.x + cornerRadius, tr.y - cornerRadius);
    CCPoint trCenter = ccp(tr.x - cornerRadius, tr.y - cornerRadius);
    CCPoint blCenter = ccp(bl.x + cornerRadius, bl.y + cornerRadius);
    CCPoint brCenter = ccp(tr.x - cornerRadius, bl.y + cornerRadius);
    
    // populate vertices
    CCPoint vertices[] = {
        // left edge
        ccp(bl.x, bl.y + cornerRadius),
        ccp(bl.x, tr.y - cornerRadius),
        
        // top left corner
        ccpAdd(tlCenter, ccpDegree(170) * cornerRadius),
        ccpAdd(tlCenter, ccpDegree(160) * cornerRadius),
        ccpAdd(tlCenter, ccpDegree(150) * cornerRadius),
        ccpAdd(tlCenter, ccpDegree(140) * cornerRadius),
        ccpAdd(tlCenter, ccpDegree(130) * cornerRadius),
        ccpAdd(tlCenter, ccpDegree(120) * cornerRadius),
        ccpAdd(tlCenter, ccpDegree(110) * cornerRadius),
        ccpAdd(tlCenter, ccpDegree(100) * cornerRadius),
        
        // top edge
        ccp(bl.x + cornerRadius, tr.y),
        ccp(tr.x - cornerRadius, tr.y),
        
        // right top corner
        ccpAdd(trCenter, ccpDegree(80) * cornerRadius),
        ccpAdd(trCenter, ccpDegree(70) * cornerRadius),
        ccpAdd(trCenter, ccpDegree(60) * cornerRadius),
        ccpAdd(trCenter, ccpDegree(50) * cornerRadius),
        ccpAdd(trCenter, ccpDegree(40) * cornerRadius),
        ccpAdd(trCenter, ccpDegree(30) * cornerRadius),
        ccpAdd(trCenter, ccpDegree(20) * cornerRadius),
        ccpAdd(trCenter, ccpDegree(10) * cornerRadius),
        
        // right edge
        ccp(tr.x, tr.y - cornerRadius),
        ccp(tr.x, bl.y + cornerRadius),
        
        // bottom right corner
        ccpAdd(brCenter, ccpDegree(-10) * cornerRadius),
        ccpAdd(brCenter, ccpDegree(-20) * cornerRadius),
        ccpAdd(brCenter, ccpDegree(-30) * cornerRadius),
        ccpAdd(brCenter, ccpDegree(-40) * cornerRadius),
        ccpAdd(brCenter, ccpDegree(-50) * cornerRadius),
        ccpAdd(brCenter, ccpDegree(-60) * cornerRadius),
        ccpAdd(brCenter, ccpDegree(-70) * cornerRadius),
        ccpAdd(brCenter, ccpDegree(-80) * cornerRadius),
        
        // bottom edge
        ccp(tr.x - cornerRadius, bl.y),
        ccp(bl.x + cornerRadius, bl.y),
        
        // bottom left corner
        ccpAdd(blCenter, ccpDegree(-100) * cornerRadius),
        ccpAdd(blCenter, ccpDegree(-110) * cornerRadius),
        ccpAdd(blCenter, ccpDegree(-120) * cornerRadius),
        ccpAdd(blCenter, ccpDegree(-130) * cornerRadius),
        ccpAdd(blCenter, ccpDegree(-140) * cornerRadius),
        ccpAdd(blCenter, ccpDegree(-150) * cornerRadius),
        ccpAdd(blCenter, ccpDegree(-160) * cornerRadius),
        ccpAdd(blCenter, ccpDegree(-170) * cornerRadius)
    };
    
    ccDrawSolidPoly(vertices, 40, ccc4FFromccc4B(color));
}