CCParticleSystem* ADParticleSystemCache::addParticleSystem( const char *pFileName )
{
	CCParticleSystem *pRetPart = NULL;
	ParticleSystemBatchMap::iterator iter = m_particleBatchesIdle.find( pFileName );
	if( iter == m_particleBatchesIdle.end() )
	{
		pRetPart = CCParticleSystemQuad::create( pFileName );
		CCParticleBatchNode *pNode = CCParticleBatchNode::createWithTexture( pRetPart->getTexture(), 100 );
		m_pRootNode->addChild( pNode );
		pNode->addChild( pRetPart );

		m_particleBatchesUsed[pFileName]._pBatchNode = pNode;

		m_particleBatchesIdle[pFileName]._pBatchNode = pNode;
	}
	else
	{
		if( iter->second._particleSystems.empty() )
		{
			pRetPart = _createNewParticleSystem( pFileName, iter->second._pBatchNode );
			iter->second._particleSystems.push_back( pRetPart );
		}
		else
		{
			pRetPart = iter->second._particleSystems.front();
			iter->second._particleSystems.pop_front();
		}
	}

	CCAssert( pRetPart != NULL, " add particle system error " );

	m_particleBatchesUsed[pFileName]._particleSystems.push_back( pRetPart );

	return pRetPart;
}
CCParticleBatchNode* CCParticleBatchNode::create(const char* imageFile, unsigned int capacity/* = kCCParticleDefaultCapacity*/)
{
    CCParticleBatchNode * p = new CCParticleBatchNode();
    if( p && p->initWithFile(imageFile, capacity))
    {
        p->autorelease();
        return p;
    }
    CC_SAFE_DELETE(p);
    return NULL;
}
CCParticleBatchNode* CCParticleBatchNode::createWithTexture(CCTexture2D *tex, unsigned int capacity/* = kCCParticleDefaultCapacity*/)
{
    CCParticleBatchNode * p = new CCParticleBatchNode();
    if( p && p->initWithTexture(tex, capacity))
    {
        p->autorelease();
        return p;
    }
    CC_SAFE_DELETE(p);
    return NULL;
}
/*
 * creation with CCTexture2D
 */
CCParticleBatchNode* CCParticleBatchNode::batchNodeWithTexture(CCTexture2D * tex)
{
    CCParticleBatchNode * p = new CCParticleBatchNode();
    if( p && p->initWithTexture(tex, kCCParticleDefaultCapacity))
    {
        p->autorelease();
        return p;
    }
    CC_SAFE_DELETE(p);
    return NULL;
}
CCParticleBatchNode* CCParticleBatchNode::batchNodeWithFile(const char* imageFile)
{
    CCParticleBatchNode * p = new CCParticleBatchNode();
    if( p && p->initWithFile(imageFile, kCCParticleDefaultCapacity))
    {
        p->autorelease();
        return p;
    }
    CC_SAFE_DELETE(p);
    return NULL;
}
Beispiel #6
0
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }
    
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

    /////////////////////////////
    // 2. add a menu item with "X" image, which is clicked to quit the program
    //    you may modify it.

    // add a "close" icon to exit the progress. it's an autorelease object
    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));

	this->addChild(pCloseItem, 10);  


	CCSprite* pSprite = CCSprite::create("IMG1.jpg");
    pSprite->setPosition(ccp(-20 + origin.x, origin.y));
	pSprite->setAnchorPoint(ccp(0, 0));
    this->addChild(pSprite, 0);


	CCParticleSystem* m_emitter1 = CCParticleSystemQuad::create("snow.plist");
    m_emitter1->retain();
    CCParticleBatchNode *batch = CCParticleBatchNode::createWithTexture(m_emitter1->getTexture());
    batch->addChild(m_emitter1);
	m_emitter1->setPosition(ccp(240, 700));
    addChild(batch, 10);
	m_emitter1->release();
	//addChild(m_emitter1);
    return true;
}
void CCParticleSystemQuad::setBatchNode(CCParticleBatchNode * batchNode)
{
    if( m_pBatchNode != batchNode ) 
    {
        CCParticleBatchNode* oldBatch = m_pBatchNode;

        CCParticleSystem::setBatchNode(batchNode);

        // NEW: is self render ?
        if( ! batchNode ) 
        {
            allocMemory();
            initIndices();
            setTexture(oldBatch->getTexture());
#if CC_TEXTURE_ATLAS_USE_VAO
            setupVBOandVAO();
#else
            setupVBO();
#endif
        }
        // OLD: was it self render ? cleanup
        else if( !oldBatch )
        {
            // copy current state to batch
            ccV3F_C4B_T2F_Quad *batchQuads = m_pBatchNode->getTextureAtlas()->getQuads();
            ccV3F_C4B_T2F_Quad *quad = &(batchQuads[m_uAtlasIndex] );
            memcpy( quad, m_pQuads, m_uTotalParticles * sizeof(m_pQuads[0]) );

            CC_SAFE_FREE(m_pQuads);
            CC_SAFE_FREE(m_pIndices);

            glDeleteBuffers(2, &m_pBuffersVBO[0]);
            memset(m_pBuffersVBO, 0, sizeof(m_pBuffersVBO));
#if CC_TEXTURE_ATLAS_USE_VAO
            glDeleteVertexArrays(1, &m_uVAOname);
            ccGLBindVAO(0);
            m_uVAOname = 0;
#endif
        }
    }
}