Exemple #1
0
CCSpriteFrame * CCNodeLoader::parsePropTypeSpriteFrame(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader, const char *pPropertyName) 
{
    CCString * spriteSheet = pCCBReader->readCachedString();
    CCString * spriteFile = pCCBReader->readCachedString();
    
    CCSpriteFrame *spriteFrame = NULL;
    if (spriteFile->length() != 0)
    {
        if (spriteSheet->length() == 0)
        {
            CCTexture2D * texture = CCTextureCache::sharedTextureCache()->addImage(spriteFile->getCString());
            CCRect bounds = CCRectMake(0, 0, texture->getContentSize().width, texture->getContentSize().height);
            spriteFrame = CCSpriteFrame::createWithTexture(texture, bounds);
        }
        else 
        {
            CCSpriteFrameCache * frameCache = CCSpriteFrameCache::sharedSpriteFrameCache();
            
            // Load the sprite sheet only if it is not loaded
            if (pCCBReader->getLoadedSpriteSheet().find(spriteSheet->getCString()) == pCCBReader->getLoadedSpriteSheet().end())
            {
                frameCache->addSpriteFramesWithFile(spriteSheet->getCString());
                pCCBReader->getLoadedSpriteSheet().insert(spriteSheet->getCString());
            }
            
            spriteFrame = frameCache->spriteFrameByName(spriteFile->getCString());
        }
        
        if (pCCBReader->getAnimatedProperties()->find(pPropertyName) != pCCBReader->getAnimatedProperties()->end())
        {
            pCCBReader->getAnimationManager()->setBaseValue(spriteFrame, pNode, pPropertyName);
        }
    }
    
    return spriteFrame;
}
void CCLobbyView::editBoxReturn(CCEditBox* editBox)
{
    CCLog("editBox %p was returned !");
    
    if( this->getEditAddress() == editBox )
    {
        CCString text = editBox->getText();
        int minIPAddressLength = 12;
        if( text.length() >= minIPAddressLength )
        {
            const char* address = text.getCString();
            this->getDisplayAddress()->setString( address );
            this->getNetwork()->setServerAddress( address );
        }
    }
}
void WordTreeScene::onSuccessComplete(const std::string& param) {
    isProcessing=true;
    
    CCDictionary* dict = CCJson::JSONObjectWithString(param.c_str());
    if( dict==NULL )
        return;
    
    CCArray* words = (CCArray*)dict->objectForKey("words");
    for( int i=0; i<words->count(); ++i ) {
        CCString* word = (CCString*)words->objectAtIndex(i);
        if( word!=NULL && word->length()>0 ) {
            CCLog("%s",word->getCString());
            WordModels::getInstance()->addWord(word->getCString());
        }
    }
    
    isProcessing = false;
}
void GameOver::onEnter()
{	
#if(CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)  
	const char* FILE_NAME = "/mnt/sdcard/ninjadash/ninjadata";
#elif(CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
	const char* FILE_NAME = "../assets/data";
#endif
	FILE* p = fopen(FILE_NAME,"r");
	if(!p)
	{
		FILE* w = fopen(FILE_NAME,"w");
		fwrite("0",1,1,w);
		fclose(w);
	}
	p = fopen(FILE_NAME,"r+");

	char data[8] = {0};
	fread(data,1,8,p);
	
	CCString* sMax = CCString::create(data);
	int nMax = sMax->intValue();
	if(m_nThisScore > nMax)
	{
		CCString* sWrite = CCString::createWithFormat("%d",m_nThisScore);
		fseek(p,0,SEEK_SET);
		int l = sWrite->length();
		fwrite(sWrite->getCString(),l,1,p);
	}
	fclose(p);
	// End Haha

	const float fontSize = 40.0f;
	
	CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
	CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

	if( !m_bFromMenu )
	{
		CCSprite* background = CCSprite::create( "bg_gameover.png" );
		background->setScaleX(CCEGLView::sharedOpenGLView()->getFrameSize().width / background->getContentSize().width);
		background->setScaleY(CCEGLView::sharedOpenGLView()->getFrameSize().height / background->getContentSize().height);
		background->setPosition( ccp( CCEGLView::sharedOpenGLView()->getFrameSize().width / 2, CCEGLView::sharedOpenGLView()->getFrameSize().height / 2 ) );
		this->addChild( background, -1 );

		// Create 2 Menu Items
		CCMenuItemImage* quitItem = CCMenuItemImage::create( "quit_up.png", "quit_down.png" );
		quitItem->setTag( MT_Menu );
		quitItem->setTarget( this, menu_selector( GameOver::menuCallback ) );
		quitItem->setPosition( ccp( visibleSize.width * (1.0 - 0.3) / 2, CCEGLView::sharedOpenGLView()->getFrameSize().height * 0.375 ) );
		quitItem->setScale( 1.5f );

		CCMenuItemImage* retryItem = CCMenuItemImage::create( "tryagain_up.png", "tryagain_down.png" );
		retryItem->setTag( MT_Retry );
		retryItem->setTarget( this, menu_selector( GameOver::menuCallback ) );
		retryItem->setPosition( ccp( visibleSize.width * (1.0 + 0.3) / 2, CCEGLView::sharedOpenGLView()->getFrameSize().height * 0.375 ) );
		retryItem->setScale( 1.5f );

		// Add to Menu
		CCMenu* pMenu = CCMenu::create( quitItem, retryItem, NULL );
		pMenu->setPosition( CCPointZero );
		this->addChild( pMenu );

		
		// Font
		CCString* s1 = CCString::createWithFormat("%d",m_nThisScore);
		CCLabelTTF* info1 = CCLabelTTF::create(s1->getCString(),"Stencil Std",fontSize);
		info1->setPosition(CCPoint(CCEGLView::sharedOpenGLView()->getFrameSize().width / 2,CCEGLView::sharedOpenGLView()->getFrameSize().height * 1.35 / 2 ));
		addChild(info1);
		
		CCLabelTTF* info2 = CCLabelTTF::create(sMax->getCString(),"Stencil Std",fontSize);
		info2->setPosition(CCPoint(CCEGLView::sharedOpenGLView()->getFrameSize().width / 2,CCEGLView::sharedOpenGLView()->getFrameSize().height * 1.1 / 2 ));
		addChild(info2);

	}
	else
	{
		CCSprite* background = CCSprite::create( "bg_setting.png" );
		background->setScaleX(CCEGLView::sharedOpenGLView()->getFrameSize().width / background->getContentSize().width);
		background->setScaleY(CCEGLView::sharedOpenGLView()->getFrameSize().height / background->getContentSize().height);
		background->setPosition( ccp( CCEGLView::sharedOpenGLView()->getFrameSize().width / 2, CCEGLView::sharedOpenGLView()->getFrameSize().height / 2 ) );
		this->addChild( background, -1 );
		
		CCSprite* bscore = CCSprite::create( "bestscore.png" );
		bscore->setScale(1.5);
		bscore->setPosition( ccp( CCEGLView::sharedOpenGLView()->getFrameSize().width / 2, CCEGLView::sharedOpenGLView()->getFrameSize().height * 0.8 ) );
		this->addChild( bscore, -1 );
	
		// Create 2 Menu Items
		CCMenuItemImage* backItem = CCMenuItemImage::create( "back_up.png", "back_down.png" );
		backItem->setTag( MT_Back );
		backItem->setTarget( this, menu_selector( GameOver::menuCallback ) );
		backItem->setPosition( ccp( visibleSize.width / 2, CCEGLView::sharedOpenGLView()->getFrameSize().height * 0.375 ) );
		backItem->setScale( 1.5f );

		// Add to Menu
		CCMenu* pMenu = CCMenu::create( backItem, NULL );
		pMenu->setPosition( CCPointZero );
		this->addChild( pMenu );

		CCLabelTTF* info2 = CCLabelTTF::create(sMax->getCString(),"Stencil Std",fontSize);
		info2->setPosition(CCPoint(CCEGLView::sharedOpenGLView()->getFrameSize().width / 2,CCEGLView::sharedOpenGLView()->getFrameSize().height * 1.4 / 2 ));
		addChild(info2);

	}

	CCLayer::onEnter();
}
Exemple #5
0
void CCSWFNodeExt::handleFrameChanged(cocos2d::CCObject * obj){
    CCSWFNode * node = (CCSWFNode *)obj;
    if (m_logicDict) {
        
        CocosDenshion::SimpleAudioEngine * audioEngine = CocosDenshion::SimpleAudioEngine::sharedEngine();
        std::stringstream frameKey;
        frameKey << (node->getCurrentFrame() + 1);
        CCDictionary * dict = (CCDictionary *)m_logicDict->objectForKey(frameKey.str());
        if (dict) {
            //切换背景音乐
            CCString * music = (CCString *)dict->objectForKey("music");
            if (music && m_music.compare(music->m_sString) != 0) {
                m_music = music->m_sString;
                if (m_music.length() > 0) {
                    CCLOG("CSWFNodeExt::handleFrameChanged %d playBackgroundMusic %s",node->getCurrentFrame(),m_music.c_str());
                    audioEngine->stopBackgroundMusic(true);
                    audioEngine->preloadBackgroundMusic(m_music.c_str());
                    audioEngine->playBackgroundMusic(m_music.c_str(),true);
                }
            }
            
            //播放音效
            CCString * effect = (CCString *)dict->objectForKey("effect");
            if (effect && effect->length() > 0) {
                const std::string tag = "#";
                std::string srcString = effect->m_sString;
                size_t startPos = srcString.find_first_of(tag);
                if (startPos != std::string::npos) {
                    std::string tmp;
                    do {
                        tmp = srcString.substr(0,startPos);
                        CCLOG("CSWFNodeExt::handleFrameChanged %d playEffect %s",node->getCurrentFrame(),tmp.c_str());
                        audioEngine->preloadEffect(tmp.c_str());
                        audioEngine->playEffect(tmp.c_str(), false);
                        srcString = srcString.substr(startPos+tag.length());
                        startPos = srcString.find_first_of(tag);
                        if(startPos == std::string::npos){
                            CCLOG("CSWFNodeExt::handleFrameChanged %d playEffect %s",node->getCurrentFrame(),tmp.c_str());
                            audioEngine->preloadEffect(tmp.c_str());
                            audioEngine->playEffect(tmp.c_str(), false);
                        }
                    } while(startPos != std::string::npos) ;
                }else{
                    CCLOG("CSWFNodeExt::handleFrameChanged %d playEffect %s",node->getCurrentFrame(),srcString.c_str());
                    audioEngine->preloadEffect(srcString.c_str());
                    audioEngine->playEffect(srcString.c_str(), false);
                }
            }
        }
        
        if (node->getCurrentFrame() == node->getFrameCount() - 1) {
            audioEngine->stopAllEffects();
            if (m_stopBgMusic) {
               audioEngine->stopBackgroundMusic(true);
            }
            CCObject * effectFile = NULL;
            CCARRAY_FOREACH(m_loadEffects, effectFile){
                audioEngine->unloadEffect(((CCString *)effectFile)->getCString());
            }
            m_loadEffects->removeAllObjects();
        }