Example #1
0
//----------------------------------------------------------
//
//
void PetDatablock::addSkillExp( int skillExp, CCPoint pos )
{
	petskillexppond += skillExp;
	if( petskillexppond >= MAX_SKILL_EXP )
	{
		petskillexppond = MAX_SKILL_EXP;
	}

	CCNode *pNode = CCNode::node();
	
	string path = GetGameImagesPath();
    path = path + "upskillexp.png";
	CCSprite* pSpriteBG = CCSprite::spriteWithFile( path.c_str() );
	pSpriteBG->setPosition( pos );

	pNode->addChild( pSpriteBG, 100 );

	char buffer[128];
	sprintf( buffer,"+%d", skillExp );
	CCLabelTTF *pLabelTTF = CCLabelTTF::labelWithString( buffer, kFontSystem[FONT_MED].fontName, kFontSystem[FONT_MED].fontSize );
	pLabelTTF->setPosition( ccp( pSpriteBG->getPosition().x + pSpriteBG->getTextureRect().size.width / 2, pSpriteBG->getPosition().y )  );
	pLabelTTF->setAnchorPoint( ccp( 0,0.5 ) );
	pNode->addChild( pLabelTTF,100 );

	CCDirector::sharedDirector()->getRunningScene()->addChild( pNode, 100 );

	pSpriteBG->runAction(CCFadeOut::actionWithDuration(3.0));
	pLabelTTF->runAction(CCFadeOut::actionWithDuration(3.0));
	CCMoveBy *pMoveBy = CCMoveBy::actionWithDuration( 2.0, ccp( 0, CCDirector::sharedDirector()->getWinSize().height / 3 ) );
    pNode->runAction( pMoveBy );

}
Example #2
0
void HudUILayer::initData()
{
    // 英雄和敌人的状态显示
    m_pRoleState = CharacterState::createRole();
    this->addChild(m_pRoleState);
    
    m_pRobotState = CharacterState::createRobot();
    this->addChild(m_pRobotState);
    
    CCNode* joyPad = CCNode::create();
    // 英雄控制器
    m_roleJoyPad = RoleJoyPad::create();
    m_roleJoyPad->setPosition(ccpSub(m_ptCenter, ccp( 288, 404)));
    joyPad->addChild(m_roleJoyPad);
    
    // 敌人控制器
    m_enemyJoyPad = EnemyJoyPad::create();
    m_enemyJoyPad->setPosition(ccpAdd(m_ptCenter, ccp(132, 290)));
    joyPad->addChild(m_enemyJoyPad);
    
    // 结算UI
    m_gameOver = GameOver::create();
    this->addChild(m_gameOver, 4);

    this->addChild(joyPad);
}
Example #3
0
//-----------------------------------------------------------
//
//
void PetDatablock::addPetMoney( int data, CCPoint pos )
{
	petmoney += data;

	CCNode *pNode = CCNode::node();
	
	string path = GetGameImagesPath();
    path = path + "upmoney.png";
	CCSprite* pSpriteBG = CCSprite::spriteWithFile( path.c_str() );
	pSpriteBG->setPosition( pos );

	pNode->addChild( pSpriteBG, 100 );

	char buffer[128];
	sprintf( buffer,"+%d", data );
	CCLabelTTF *pLabelTTF = CCLabelTTF::labelWithString( buffer, kFontSystem[FONT_MED].fontName, kFontSystem[FONT_MED].fontSize );
	pLabelTTF->setPosition( ccp( pSpriteBG->getPosition().x + pSpriteBG->getTextureRect().size.width / 2, pSpriteBG->getPosition().y )  );
	pLabelTTF->setAnchorPoint( ccp( 0,0.5 ) );
	pNode->addChild( pLabelTTF,100 );

	CCDirector::sharedDirector()->getRunningScene()->addChild( pNode, 100 );

	pSpriteBG->runAction(CCFadeOut::actionWithDuration(3.0));
	pLabelTTF->runAction(CCFadeOut::actionWithDuration(3.0));

	CCMoveBy *pMoveBy = CCMoveBy::actionWithDuration( 2.0, ccp( 0, CCDirector::sharedDirector()->getWinSize().height / 3 ) );
    pNode->runAction( pMoveBy );

	if( CCUserDefault::sharedUserDefault()->getBoolForKey( "sound" ) )
	{
		CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("data/audio/money.mp3", false);
	}
}
Example #4
0
//--------------------------------------------------------------
//
//
void PetDatablock::addPlayerMoney( int data, CCPoint pos )
{
	playershoppingmallmoney += data;

	CCNode *pNode = CCNode::node();
	
	string path = GetGameImagesPath();
    path = path + "upPlayerMoney.png";
	CCSprite* pSpriteBG = CCSprite::spriteWithFile( path.c_str() );
	pSpriteBG->setPosition( pos );

	pNode->addChild( pSpriteBG, 100 );

	char buffer[128];
	sprintf( buffer,"+%d", data );
	CCLabelTTF *pLabelTTF = CCLabelTTF::labelWithString( buffer, kFontSystem[FONT_MED].fontName, kFontSystem[FONT_MED].fontSize );
	pLabelTTF->setPosition( ccp( pSpriteBG->getPosition().x + pSpriteBG->getTextureRect().size.width / 2, pSpriteBG->getPosition().y )  );
	pLabelTTF->setAnchorPoint( ccp( 0,0.5 ) );
	pNode->addChild( pLabelTTF,100 );

	CCDirector::sharedDirector()->getRunningScene()->addChild( pNode, 100 );

	pSpriteBG->runAction(CCFadeOut::actionWithDuration(3.0));
	pLabelTTF->runAction(CCFadeOut::actionWithDuration(3.0));

	CCMoveBy *pMoveBy = CCMoveBy::actionWithDuration( 2.0, ccp( 0, CCDirector::sharedDirector()->getWinSize().height / 3 ) );
    pNode->runAction( pMoveBy );
}
Example #5
0
void CHandBookPanel::updateShowArea()
{
	CCNode* pLayer = m_ui;

	if(m_pHeroLayer) m_pHeroLayer->setVisible(false);
	if(m_pMonsterLayer) m_pMonsterLayer->setVisible(false);
	if(m_pEquipLayer)m_pEquipLayer->setVisible(false);

	switch (m_iType)
	{
	case HandBookTabHero:
		{
			if(!m_pHeroLayer)
			{
				m_pHeroLayer = CHandBookHeroLayer::create();
				m_pHeroLayer->setTouchPriority(LayerManager::instance()->getPriority()-1);
				pLayer->addChild(m_pHeroLayer);
				m_pHeroLayer->setPosition(pLayer->convertToNodeSpace(m_pHeroLayer->getPosition()));
				AskForHandBook(m_iType);
			}
			else
			{
				m_pHeroLayer->setVisible(true);
			}
		}
		break;
	case HandBookTabMonster:
		{
			if(!m_pMonsterLayer)
			{
				m_pMonsterLayer = CHandBookMonsterLayer::create();
				m_pMonsterLayer->setTouchPriority(LayerManager::instance()->getPriority()-1);
				pLayer->addChild(m_pMonsterLayer);
				m_pMonsterLayer->setPosition(pLayer->convertToNodeSpace(m_pMonsterLayer->getPosition()));
				AskForHandBook(m_iType);
			}
			m_pMonsterLayer->setVisible(true);
		}
		break;
	case HandBookTabEquip:
		{
			if(!m_pEquipLayer)
			{
				m_pEquipLayer = CHandBookEquipLayer::create();
				m_pEquipLayer->setTouchPriority(LayerManager::instance()->getPriority()-1);
				pLayer->addChild(m_pEquipLayer);
				m_pEquipLayer->setPosition(pLayer->convertToNodeSpace(m_pEquipLayer->getPosition()));
				AskForHandBook(m_iType);
			}
			m_pEquipLayer->setVisible(true);
		}
		break;
	case HandBookTabMax:
		break;
	default:
		break;
	}
}
Example #6
0
TextLayer::TextLayer(void)
{
	initWithColor( ccc4(32,32,32,255) );
		
	float x,y;
	
	CGSize size = CCDirector::sharedDirector()->getWinSize();
	x = size.width;
	y = size.height;
	
	CCNode* node = CCNode::node();
	CCActionInterval* effect = getAction();
	node->runAction(effect)
		;
	addChild(node, 0, kTagBackground);
	
	CCSprite *bg = CCSprite::spriteWithFile(s_back3);
	node->addChild(bg, 0);
	bg->setAnchorPoint( CGPointZero );

	CCSprite* grossini = CCSprite::spriteWithFile(s_pPathSister2);
	node->addChild(grossini, 1);
	grossini->setPosition( CGPointMake(x/3,y/2) );
	CCActionInterval* sc = CCScaleBy::actionWithDuration(2, 5);
	CCActionInterval* sc_back = sc->reverse();
	grossini->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)(CCSequence::actions(sc, sc_back, NULL)) ) );

	CCSprite* tamara = CCSprite::spriteWithFile(s_pPathSister1);
	node->addChild(tamara, 1);
	tamara->setPosition( CGPointMake(2*x/3,y/2) );
	CCActionInterval* sc2 = CCScaleBy::actionWithDuration(2, 5);
	CCActionInterval* sc2_back = sc2->reverse();
	tamara->runAction( CCRepeatForever::actionWithAction((CCActionInterval*)(CCSequence::actions(sc2, sc2_back, NULL))) );
	
	CCLabelTTF* label = CCLabelTTF::labelWithString((effectsList[actionIdx]).c_str(), "Marker Felt", 32);
	
	label->setPosition( CGPointMake(x/2,y-80) );
	addChild(label);
	label->setTag( kTagLabel );

	CCMenuItemImage *item1 = CCMenuItemImage::itemFromNormalImage(s_pPathB1, s_pPathB2, this, menu_selector(TextLayer::backCallback) );
	CCMenuItemImage *item2 = CCMenuItemImage::itemFromNormalImage(s_pPathR1, s_pPathR2, this, menu_selector(TextLayer::restartCallback) );
	CCMenuItemImage *item3 = CCMenuItemImage::itemFromNormalImage(s_pPathF1, s_pPathF2, this, menu_selector(TextLayer::nextCallback) );

	CCMenu *menu = CCMenu::menuWithItems(item1, item2, item3, NULL);

	menu->setPosition( CGPointZero );
	item1->setPosition( CGPointMake( size.width/2 - 100,30) );
	item2->setPosition( CGPointMake( size.width/2, 30) );
	item3->setPosition( CGPointMake( size.width/2 + 100,30) );
	
	addChild(menu, 1);	

	schedule( schedule_selector(TextLayer::checkAnim) );
}
void ParkingViewScene::LoadParkingId()
{
    CCNode* node = this->getChildByTag(250);
    char s[20] ;

    sprintf(s, "%d.png", this->wayPointID);
    
    CCSprite *sprtEstabelecimento = CCSprite::create(s);
    if( sprtEstabelecimento == 0)
        sprtEstabelecimento = CCSprite::create("ModeloWayPointFoto.png");
    
    sprtEstabelecimento->setAnchorPoint(ccp(0,0));
    sprtEstabelecimento->setPosition(ccp(0,217));
    node->addChild(sprtEstabelecimento);

    
    //Waypoints do estacionamentos sao referidos como retirada de veiculos, de acordo
    //com o id, aqui o texto é alterado.
    switch(wayPointID)
    {
        case 19:
            insertLabel(ccc3(72, 72, 72), ccp(20, 180), true, "Bloco A1", node, 16);
            break;
        case 51:
            insertLabel(ccc3(72, 72, 72), ccp(20, 180), true, "Bloco B", node, 16);
            break;
        case 89:
            insertLabel(ccc3(72, 72, 72), ccp(20, 180), true, "Bloco D/E", node, 16);
            break;
    }
 

    //Cria um label ( aqui vira descricao do estacionamento)
    insertLabel(ccc3(72, 72, 72), ccp(20, 160), false, "Auditorio Moise Safra", node, 12);
    
    CCSprite *btnHorarioSelected = CCSprite::create("btnShowRotaEstacionmanto.png"); // botao pressionado
    CCSprite *btnHorarioUnSelected = CCSprite::create("btnShowRotaEstacionmanto.png");//botao nao pressionado
    CCMenuItemSprite *itembtnHorario = CCMenuItemSprite::create(btnHorarioSelected, btnHorarioUnSelected, btnHorarioSelected, menu_selector(ParkingViewScene::btnRotaCallBack));
	itembtnHorario->setAnchorPoint(ccp(0, 0));
    itembtnHorario->setPosition(ccp(40, 0));
    
    CCMenu* options = CCMenu::create();
    options->addChild(itembtnHorario,0,wayPointID);
    options->setPosition(ccp(230, 171) );
    node->addChild(options);
    
    CCSprite *sprtFundoEstabelecimento = CCSprite::create("SombraMagica.png");
    sprtFundoEstabelecimento->setAnchorPoint(ccp(0,0));
    sprtFundoEstabelecimento->setPosition(ccp(72, 200));
    node->addChild(sprtFundoEstabelecimento);
}
CCMenuItemSprite* BetControler::createRadioButton(const char* label,const char* normal,const char* selected,const char* disabled/*=NULL*/,const char* disabledLabel/*=NULL*/){
	if(normal==NULL){
		return NULL;
	}

	CCNode* node = CCNode::create();
	CCSprite* sprite = ResourceManager::getInstance()->createSprite(this, normal);
	CCSprite* labelSprite = ResourceManager::getInstance()->createSprite(this, label);
	node->setContentSize(CCSizeMake(90+labelSprite->getContentSize().width, 110));
	node->addChild(sprite);
	node->addChild(labelSprite);
	LayoutUtil::layoutParentLeft(sprite);
	LayoutUtil::layoutParentLeft(labelSprite,90);
	CCNode* downNode=node;
	if(selected!=NULL){
		downNode = CCNode::create();
		CCSprite* downSprite = ResourceManager::getInstance()->createSprite(this, selected);
		CCSprite* labeldownSprite = ResourceManager::getInstance()->createSprite(this, label);
		downNode->setContentSize(CCSizeMake(90+labeldownSprite->getContentSize().width, 110));
		downNode->addChild(downSprite);
		downNode->addChild(labeldownSprite);
		LayoutUtil::layoutParentLeft(downSprite);
		LayoutUtil::layoutParentLeft(labeldownSprite,90);
	}

	CCNode* disabledNode=NULL;
	if(disabled!=NULL){
		disabledNode = CCNode::create();
		disabledNode->setContentSize(CCSizeMake(104, 104));
		CCSprite* disabledSprite = ResourceManager::getInstance()->createSprite(this, disabled);
		CCSprite* labelDisabledSprite = ResourceManager::getInstance()->createSprite(this, disabledLabel);
		disabledNode->addChild(disabledSprite);
		disabledNode->addChild(labelDisabledSprite);
		LayoutUtil::layoutParentLeft(disabledSprite);
		LayoutUtil::layoutParentLeft(labelDisabledSprite,90);
	}

	CCMenuItemSprite* button=NULL;
	if(disabledNode==NULL){
		button=CCMenuItemSprite::create(node,downNode, this, menu_selector(BetControler::radioButtonsCallback));
	}else{
		button=CCMenuItemSprite::create(node,downNode,disabledNode, this, menu_selector(BetControler::radioButtonsCallback));
	}

	registerMenuItem(button);
	this->addChild(button);
	//button->unselected();
	button->setVisible(false);
	return button;
}
Example #9
0
TextLayer::TextLayer(void)
{
    initWithColor( ccc4(32,128,32,255) );
    
    CCNode* node = CCNode::create();
    CCActionInterval* effect = getAction();
    node->runAction(effect);
    addChild(node, 0, kTagBackground);
    
    CCSprite *bg = CCSprite::create(s_back3);
    node->addChild(bg, 0);
//  bg->setAnchorPoint( CCPointZero );
    bg->setPosition(VisibleRect::center());

    CCSprite* grossini = CCSprite::create(s_pPathSister2);
    node->addChild(grossini, 1);
    grossini->setPosition( ccp(VisibleRect::left().x+VisibleRect::getVisibleRect().size.width/3,VisibleRect::center().y) );
    CCActionInterval* sc = CCScaleBy::create(2, 5);
    CCActionInterval* sc_back = sc->reverse();
    grossini->runAction( CCRepeatForever::create(CCSequence::create(sc, sc_back, NULL) ) );

    CCSprite* tamara = CCSprite::create(s_pPathSister1);
    node->addChild(tamara, 1);
    tamara->setPosition( ccp(VisibleRect::left().x+2*VisibleRect::getVisibleRect().size.width/3,VisibleRect::center().y) );
    CCActionInterval* sc2 = CCScaleBy::create(2, 5);
    CCActionInterval* sc2_back = sc2->reverse();
    tamara->runAction( CCRepeatForever::create(CCSequence::create(sc2, sc2_back, NULL)) );
    
    CCLabelTTF* label = CCLabelTTF::create((effectsList[actionIdx]).c_str(), "Marker Felt", 32);
    
    label->setPosition( ccp(VisibleRect::center().x,VisibleRect::top().y-80) );
    addChild(label);
    label->setTag( kTagLabel );

    CCMenuItemImage *item1 = CCMenuItemImage::create(s_pPathB1, s_pPathB2, this, menu_selector(TextLayer::backCallback) );
    CCMenuItemImage *item2 = CCMenuItemImage::create(s_pPathR1, s_pPathR2, this, menu_selector(TextLayer::restartCallback) );
    CCMenuItemImage *item3 = CCMenuItemImage::create(s_pPathF1, s_pPathF2, this, menu_selector(TextLayer::nextCallback) );

    CCMenu *menu = CCMenu::create(item1, item2, item3, NULL);

    menu->setPosition(CCPointZero);
    item1->setPosition(ccp(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2));
    item2->setPosition(ccp(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2));
    item3->setPosition(ccp(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2));
    
    addChild(menu, 1);    

    schedule( schedule_selector(TextLayer::checkAnim) );
}
Example #10
0
CCNode *APSSprite::createNode() {
    CCNode *node = APSGraphic::createNode();
    APSImageHolder *ih = this->getImageHolder();
    CCSize contentSize;
    CCSize targetSize = APSPlatform::sharedPlatform()->convertSizeToPixels(this->getSize());
    
    if (ih) {
        this->m_spriteNode = new CCSprite;
        if (this->getIsAnimatable()) {
            // Create animation sprite
            APSSpriteSheetHolder *sh = (APSSpriteSheetHolder *)ih;
            CCSpriteFrame *spriteFrame = sh->getCCSpriteFrameAtIndex(((APSGraphicGroup *)this->getParent())->getDisplayedFrameIndex());
            
#if COCOS2D_VERSION >= 0x00020000
            CCSpriteBatchNode *spriteSheet = CCSpriteBatchNode::createWithTexture(ih->getTexture(), sh->getCount());
#else
            CCSpriteBatchNode *spriteSheet = CCSpriteBatchNode::batchNodeWithTexture(ih->getTexture(), sh->getCount());
#endif//APS_SKIP
            this->m_node->addChild(spriteSheet);
            
            this->m_spriteNode->initWithSpriteFrame(spriteFrame);
            spriteSheet->addChild(this->m_spriteNode);
            
            CCSize size = this->m_spriteNode->getContentSize();
            contentSize = APSPlatform::sharedPlatform()->convertSizeToPixels(size);
            
        } else {
            // Check if there is a sprite frame in sprite frame cache.
            CCSpriteFrame *frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(this->getImageHolder()->getRuntimeFilename().c_str());
            if (frame) {
                // Use the sprite frame
                this->m_spriteNode->initWithSpriteFrame(frame);
                contentSize = frame->getOriginalSizeInPixels();
                node->addChild(this->m_spriteNode);
            } else {
                // Normal sprite
                this->m_spriteNode->initWithTexture(ih->getTexture());
                contentSize = ih->getTexture()->getContentSizeInPixels();
                node->addChild(this->m_spriteNode);
            }
        }
        
        // scale the sprite to match the sizes of texture and sprite
        this->m_spriteNode->setScaleX(targetSize.width/contentSize.width);
        this->m_spriteNode->setScaleY(targetSize.height/contentSize.height);
    }

    return node;
}
bool CCControlPotentiometerTest::init()
{
    if (CCControlScene::init())
    {
        CCSize screenSize = CCDirector::sharedDirector()->getWinSize();
        
        CCNode *layer = CCNode::create();
        layer->setPosition(ccp (screenSize.width / 2, screenSize.height / 2));
        this->addChild(layer, 1);
        
        double layer_width = 0;
        
        // Add the black background for the text
        CCScale9Sprite *background  = CCScale9Sprite::create("extensions/buttonBackground.png");
        background->setContentSize(CCSizeMake(80, 50));
        background->setPosition(ccp(layer_width + background->getContentSize().width / 2.0f, 0));
        layer->addChild(background);
        
        layer_width += background->getContentSize().width;
        
        this->setDisplayValueLabel(CCLabelTTF::create("", "HelveticaNeue-Bold", 30));

        m_pDisplayValueLabel->setPosition(background->getPosition());
        layer->addChild(m_pDisplayValueLabel);
		
        // Add the slider
        CCControlPotentiometer *potentiometer = CCControlPotentiometer::create("extensions/potentiometerTrack.png"
                                                                                ,"extensions/potentiometerProgress.png"
                                                                                ,"extensions/potentiometerButton.png");
        potentiometer->setPosition(ccp (layer_width + 10 + potentiometer->getContentSize().width / 2, 0));

        // When the value of the slider will change, the given selector will be call
        potentiometer->addTargetWithActionForControlEvents(this, cccontrol_selector(CCControlPotentiometerTest::valueChanged), CCControlEventValueChanged);
        
		layer->addChild(potentiometer);
        
        layer_width += potentiometer->getContentSize().width;
        
        // Set the layer size
        layer->setContentSize(CCSizeMake(layer_width, 0));
        layer->setAnchorPoint(ccp (0.5f, 0.5f));
        
        // Update the value label
        this->valueChanged(potentiometer, CCControlEventValueChanged);
        return true;
	}
	return false;
}
Example #12
0
cocos2d::CCNode* ComponentsTestLayer::createGameScene()
{
    CCNode *root = NULL;
    do 
	{
        CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
        CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

       
        CCSprite *player = CCSprite::create("components/Player.png", CCRectMake(0, 0, 27, 40) );
        
        player->setPosition( ccp(origin.x + player->getContentSize().width/2,
                                 origin.y + visibleSize.height/2) );
        
        root = cocos2d::CCNode::create();
        root->addChild(player, 1, 1);
        

        CCMenuItemFont *itemBack = CCMenuItemFont::create("Back", this, menu_selector(ComponentsTestLayer::toExtensionsMainLayer));
        itemBack->setColor(ccc3(0, 0, 0));
        itemBack->setPosition(ccp(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25));
        CCMenu *menuBack = CCMenu::create(itemBack, NULL);
        menuBack->setPosition(CCPointZero);
        addChild(menuBack);
        
    }while (0);
    
    return root;
}
cocos2d::CCNode* SceneEditorTestLayer::createGameScene()
{
    CCNode *pNode = CCJsonReader::sharedJsonReader()->createNodeWithJsonFile("FishJoy2.json");
	if (pNode == NULL)
	{
		return NULL;
	}
	m_pCurNode = pNode;

	//play back music
    CCComAudio *pAudio = (CCComAudio*)(pNode->getComponent("Audio"));
	pAudio->playBackgroundMusic(pAudio->getFile(), pAudio->getIsLoop());

	//fishes
	CCArmature *pBlowFish = getFish(5, "blowFish");
	CCArmature *pButterFlyFish = getFish(6, "butterFlyFish");
	pBlowFish->getAnimation()->playByIndex(0);
	pButterFlyFish->getAnimation()->playByIndex(0);

    CCMenuItemFont *itemBack = CCMenuItemFont::create("Back", this, menu_selector(SceneEditorTestLayer::toExtensionsMainLayer));
        itemBack->setColor(ccc3(255, 255, 255));
        itemBack->setPosition(ccp(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25));
        CCMenu *menuBack = CCMenu::create(itemBack, NULL);
        menuBack->setPosition(CCPointZero);
		menuBack->setZOrder(4);

    pNode->addChild(menuBack);
    
	//ui action
	cocos2d::extension::UIActionManager::shareManager()->PlayActionByName("startMenu_1.json","Animation1");

    return pNode;
}
Example #14
0
cocos2d::CCNode* SceneEditorTestLayer::createGameScene()
{
    CCNode *pNode = CCSSceneReader::sharedSceneReader()->createNodeWithSceneFile("scenetest/FishJoy2.json");
    if (pNode == NULL)
    {
        return NULL;
    }
    m_pCurNode = pNode;

    //fishes
    CCArmature *pBlowFish = getFish(10008, "blowFish");
    CCArmature *pButterFlyFish = getFish(10009, "butterFlyFish");
    pBlowFish->getAnimation()->playByIndex(0);
    pButterFlyFish->getAnimation()->playByIndex(0);

    CCMenuItemFont *itemBack = CCMenuItemFont::create("Back", this, menu_selector(SceneEditorTestLayer::toExtensionsMainLayer));
    itemBack->setColor(ccc3(255, 255, 255));
    itemBack->setPosition(ccp(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25));
    CCMenu *menuBack = CCMenu::create(itemBack, NULL);
    menuBack->setPosition(CCPointZero);
    menuBack->setZOrder(4);

    pNode->addChild(menuBack);

    //ui action
    cocos2d::extension::UIActionManager::shareManager()->PlayActionByName("startMenu_1.json","Animation1");

    return pNode;
}
Example #15
0
void Image::loadAnimation(const char* filename, int capacity)
{
    imageFile = filename;
    spriteSheet = CCSpriteBatchNode::create(imageFile.append(".png").c_str(), capacity);
    imageFile.erase(imageFile.length() - 4, 4);
    spriteSheet->retain();
    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(imageFile.append(".plist").c_str());
    imageFile.erase(imageFile.length() - 6, 6);
    
    spritesName = CCArray::createWithCapacity(capacity);
    spritesName->retain();
    for(int i = 1; i <= capacity; i++)
    {
        /*char num[10];
         sprintf(num, "%04d", i);*/
        spritesName->addObject(ScreateF("%s_%02d.png", filename, i));//imageFile.append(num).append(".png")));
    }
    CCSpriteFrame* firstFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(((CCString*)spritesName->objectAtIndex(0))->getCString());
    delegate->setDisplayFrame(firstFrame);
    CCNode* parent = delegate->getParent();
    parent->addChild(spriteSheet);
    parent->removeChild(delegate, false);
    spriteSheet->addChild(delegate);
    runningAnimation = NULL;
}
Example #16
0
int XFightView::LuaAddToNode(lua_State* L)
{
	int				nTop			= lua_gettop(L);
	const char*		pszInstanceName	= NULL;
	const char*		pszNodeName		= NULL;
	BasicPanel*		pInstance		= NULL;
	CCNode*			pNode			= NULL;

	XYLOG_FAILED_JUMP(nTop == 2);

	pszInstanceName = lua_tostring(L, 1);
	XYLOG_FAILED_JUMP(pszInstanceName);

	pInstance = g_UIManager->GetInstanceByRootName(pszInstanceName);
	XYLOG_FAILED_JUMP(pInstance);

	pszNodeName = lua_tostring(L, 2);
	XYLOG_FAILED_JUMP(pszNodeName);

	pNode = pInstance->m_mapMemberVariable[pszNodeName];
	XYLOG_FAILED_JUMP(pNode);

	pNode->addChild(this);
Exit0:
	return 0;
}
Example #17
0
void IPadSprite::ccTouchEnded(CCTouch* touch, CCEvent* event)
{
	CCNode* pNode = this->getParent();
	CCNode* pNode1 = this;
	while(pNode->getParent() != NULL)
	{
		pNode1 = pNode;
		pNode = pNode->getParent();
	}
	MainScene* pScene = dynamic_cast<MainScene*>(pNode1);
	if(pScene)
	{
		pScene->hideMenu();
	}
	
	MS5Layer* pLayer = dynamic_cast<MS5Layer*>(this->getParent());
	if(pLayer)
		pLayer->hidePopupPanel();
		
	this->setIsVisible(false);
	pNode = this->getParent();
	pNode = pNode->getParent();
	
	if(pNode->getChildByTag(TAG_IPAD_BIG) == NULL)
	{
		ScaleSprite* pSprite = ScaleSprite::scaleSpriteWithFile("ipad_big.png");
		pSprite->setTag(TAG_IPAD_BIG);
		pSprite->setScale(0.24f);
		pSprite->setPosition( ccp(855, 420) );
		pNode->addChild(pSprite, 2);
		pSprite->startScale();
	}
} 
TEST( Notifier, TestOfNotificationUseAfterRelease )
{
	Notifier notifier;

	TestClazzReleased* pReleasedNode = new TestClazzReleased( notifier );
	pReleasedNode->init();

	CCNode* pHolder = new CCNode();
	pHolder->init();
	notifier.addNotification( getNotificationTestUseAfterRelease(), {pHolder, &CCNode::removeAllChildren } );

	EXPECT_EQ( 1u, pReleasedNode->retainCount() );
	EXPECT_EQ( 1u, pHolder->retainCount() );

	pHolder->addChild( pReleasedNode );

	EXPECT_EQ( 2u, pReleasedNode->retainCount() );
	EXPECT_EQ( 1u, pHolder->retainCount() );

	pReleasedNode->release();

	EXPECT_EQ( 1u, pReleasedNode->retainCount() );
	EXPECT_EQ( 1u, pHolder->retainCount() );

	//OLD: Now when we notify we have problem. We have use after release.
	//NEW: Now everything should work because we mark second notification as toRemove so we simply skip it :)
	notifier.notify( getNotificationTestUseAfterRelease() );

	pHolder->release();
}
void SpriteMonsterArcher::initEffect(unsigned int effectId)
{
	if(effectInited)
	{
		return;
	}

	effectNodes.clear();
	LevelLayer * layer = LevelManager::sShareInstance()->getCurrentLevelLayer();
	if (!layer)
	{
		ASSERT(0, "LevelLayer is NULL");
		return;
	}

	for (int i = 0; i < EFFECT_COUNT; i++)
	{
		CCNode * effectNode = CCNode::create();
		EffectSprite * skillAnim = ParticleManager::Get()->createEffectSprite(effectId,"");
		skillAnim->SetAnim(kType_Play, 1, true);
		effectNode->addChild(skillAnim);
		effectNode->setVisible(false);

		//添加到动态管理层
		
		effectNodes.push_back(effectNode);
		layer->getObjectLayer()->addChild(effectNodes[i], LevelLayer::sCalcZorder(m_oldPos));
	}
	effectInited = true;
}
Example #20
0
	CCARRAY_FOREACH(pMyChildArray, pObj)
	{
		CCNode *pAddChild = *it;
		CCNode *pChild = dynamic_cast<CCNode*>(pObj);
		pChild->addChild(pAddChild);
		++it;
	}
Example #21
0
void NestedTest::setup()
{
    static int depth = 9;
    
    CCNode *parent = this;
    
    for (int i = 0; i < depth; i++) {
                
        int size = 225 - i * (225 / (depth * 2));

        CCClippingNode *clipper = CCClippingNode::create();
        clipper->setContentSize(CCSizeMake(size, size));
        clipper->setAnchorPoint(ccp(0.5, 0.5));
        clipper->setPosition( ccp(parent->getContentSize().width / 2, parent->getContentSize().height / 2) );
        clipper->setAlphaThreshold(0.05f);
        clipper->runAction(CCRepeatForever::create(CCRotateBy::create(i % 3 ? 1.33 : 1.66, i % 2 ? 90 : -90)));
        parent->addChild(clipper);
        
        CCNode *stencil = CCSprite::create(s_pPathGrossini);
        stencil->setScale( 2.5 - (i * (2.5 / depth)) );
        stencil->setAnchorPoint( ccp(0.5, 0.5) );
        stencil->setPosition( ccp(clipper->getContentSize().width / 2, clipper->getContentSize().height / 2) );
        stencil->setVisible(false);
        stencil->runAction(CCSequence::createWithTwoActions(CCDelayTime::create(i), CCShow::create()));
        clipper->setStencil(stencil);

        clipper->addChild(stencil);
        
        parent = clipper;
    }

}
Example #22
0
void TapSprite::eraseSoldierAnim(int x,int y){
    
    status->setEraseFlg(combo, x, y);
    
    CCSprite* sprite;
    sprite = status->getSprite(x,y);
    
    CCDelayTime* delay = CCDelayTime::create(0.1875f);
    CCFiniteTimeAction* func = CCCallFuncO::create( this,callfuncO_selector(TapSprite::eraseSoldierDelay),(CCObject*)sprite) ;
    CCSequence* sequense = CCSequence::createWithTwoActions(delay,func);
    animation++;
    ((CCSprite*)sprite)->runAction(sequense);

    if(animation == 1){
        CCScaleTo* scaleTo = CCScaleTo::create(0.1825f, 1.0f);
        CCString* string = CCString::createWithFormat("%d combo",combo);
        CCLabelTTF* label = CCLabelTTF::create(string->getCString(), "arial", 18.0f);
        label->setScale(0.125f);
        label->setPosition(sprite->getPosition());
        CCNode* node = ((CCSprite*)sprite)->getParent();
        if(node){
            node->addChild(label);
            label->runAction(scaleTo);
            labelVec.push_back(label);
        }
    }
    
    status->setSprite(NULL, x, y);

}
Example #23
0
bool TapSprite::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
{
    if(status->getAnimationFlg()) return false;
    
    // タッチ開始処理
    
    // タッチ位置を取得
    CCPoint point = pTouch->getLocation();
    // スプライトの大きさ
    CCSize size = this->getTexture()->getContentSize();
    // スプライトの範囲
    CCRect rect = CCRectMake(this->getPositionX()-size.width/2, this->getPositionY()-size.height/2, size.width, size.height);
    
    // タッチ位置がスプライト内ならイベント処理するのでtrueを返す
    if(rect.containsPoint(point)){
        status->setWaitFlg(false);
        status->setChangeFlg(false);
        CCNode* parent;
        CCSprite* sprite;
        sprite = status->getSprite(thisx,thisy);
        parent = sprite->getParent();
        parent->removeChild(sprite);
        parent->addChild(sprite);
        //this->setPosition(point);
        this->setPosition(ccp(point.x,point.y + 25));
        return true;
    }else{
        return false;
    }
}
KDvoid TestBox2D::addNewSpriteWithCoords ( const CCPoint& tPosition )
{
	// Define the dynamic body.
	//Set up a 1m squared box in the physics world
	b2BodyDef  tBodyDef;
	tBodyDef.type = b2_dynamicBody;
	tBodyDef.position.Set ( tPosition.x / PTM_RATIO, tPosition.y / PTM_RATIO );
	//tBodyDef.userData = sprite;

	b2Body*  pBody = m_pWorld->CreateBody ( &tBodyDef );
	
	// Define another box shape for our dynamic body.
	b2PolygonShape  tDynamicBox;
	tDynamicBox.SetAsBox ( 0.5f, 0.5f );
	
	// Define the dynamic body fixture.
	b2FixtureDef  tFixtureDef;
	tFixtureDef.shape = &tDynamicBox;	
	tFixtureDef.density = 1.0f;
	tFixtureDef.friction = 0.3f;
	pBody->CreateFixture ( &tFixtureDef );

	CCNode*  pParent = this->getChildByTag ( kTagParentNode );

	// We have a 64x64 sprite sheet with 4 different 32x32 images.  The following code is
	// just randomly picking one of the images
	KDint  nOffsetX = ( CCRANDOM_0_1 ( ) > 0.5f ? 0 : 1 );
	KDint  nOffsetY = ( CCRANDOM_0_1 ( ) > 0.5f ? 0 : 1 );

    CCPhysicsSprite*  pSprite = CCPhysicsSprite::createWithTexture ( m_pSpriteTexture, ccr ( 32 * nOffsetX, 32 * nOffsetY, 32, 32 ) );
    pParent->addChild ( pSprite );
    pSprite->setB2Body  ( pBody );
    pSprite->setPTMRatio ( PTM_RATIO );
    pSprite->setPosition ( tPosition );
}
Example #25
0
void MessageView::CCListView_cellForRow(CCListView *listView, CCListViewProtrolData *data)
{
    // 背景
    CCSprite* cellBg = CCSprite::create("bg_listview_item.png") ;

    const float cell_width = cellBg->getContentSize().width+15 ;
    const float cell_height = cellBg->getContentSize().height+10 ;

    CCListViewCell* cell = CCListViewCell::node() ;
    cell->setContentSize(CCSizeMake(cell_width, cell_height)) ;
    cell->setOpacity(0) ;
    // cell->setSelectionColor(ccc4(255, 0, 0, 255)) ;
    cell->setSelectionColor(ccc4(103, 102, 204, 255)) ;
    data->cell = cell ;

    CCNode* cellNode = CCNode::create() ;
    cellNode->setContentSize(CCSizeMake(cell_width, cell_height)) ;
    cellNode->setAnchorPoint(ccp(0, 0)) ;
    cellNode->setPosition(ccp(0, 0)) ;
    cell->addChild(cellNode) ;

    // 背景
    cellBg->setAnchorPoint(ccp(0.5, 0.5)) ;
    cellBg->setPosition(ccp(cell_width*0.5, cell_height*0.5)) ;
    cellNode->addChild(cellBg) ;

    // icon
    CCSprite* iconMsg = CCSprite::create("icon_msg.png") ;
    iconMsg->setAnchorPoint(ccp(0, 0.5)) ;
    iconMsg->setPosition(ccp(20, cell_height*0.5)) ;
    cellNode->addChild(iconMsg, 1) ;

    // 主题
    CCLabelTTF* themeLabel = CCLabelTTF::create("蛇年贺新春,免费拿九玩币","font01.ttf", 24.0f,CCSizeMake(cell_width, 50),
                             kCCTextAlignmentLeft, kCCVerticalTextAlignmentCenter) ;
    themeLabel->setColor(ccc3(255, 215, 0)) ;
    themeLabel->setAnchorPoint(ccp(0, 1)) ;
    themeLabel->setPosition(ccp(120, cell_height-8)) ;
    cellNode->addChild(themeLabel, 1) ;

    // 内容
    CCLabelTTF* contentLabel = CCLabelTTF::create("蛇年贺新春,免费拿九玩币,蛇年贺新春,免费拿九玩币","font01.ttf", 20.0f,CCSizeMake(cell_width, 50),
                               kCCTextAlignmentLeft, kCCVerticalTextAlignmentCenter) ;
    contentLabel->setAnchorPoint(ccp(0, 0)) ;
    contentLabel->setPosition(ccp(120, 8)) ;
    cellNode->addChild(contentLabel, 1) ;
}
Example #26
0
void CChangeHeadImg::addGridCell(unsigned int uIdx, CGridViewCell* pCell)
{
	CLayout *lay = UICloneMgr::cloneLayout(m_cell);

	for (int i=1; i<=2; i++)
	{
		CCNode *child = lay->getChildByTag(i);
		lay->removeChild(child);
		pCell->addChild(child);

		if (i==1)
		{
			if (m_headIconList.at(uIdx)>0)
			{
				CImageView* pHead = CImageView::create(CCString::createWithFormat("headImg/%d.png", m_headIconList.at(uIdx))->getCString());
				if(!pHead)
				{
					pHead = CImageView::create("headImg/null.png");
					CCLOG("ERROR_____CChangeHeadImg::addGridCell");
				}
				child->addChild(pHead);
				NodeFillParent(pHead);
			}
			else
			{
				UserData *data = DataCenter::sharedData()->getUser()->getUserData();
				string fbName = data->getFbId() +".jpg";
				string fullName = CCFileUtils::sharedFileUtils()->fullPathForFilename(fbName.c_str());
				bool isFileExist = CCFileUtils::sharedFileUtils()->isFileExist(fullName);
				if(isFileExist)
				{
					CCSprite* spr =CCSprite::create(fullName.c_str());
					child->addChild(spr);
					NodeFillParent(spr);
				}
			}
			
		}
		else if(i==2)
		{
			CImageView* pBtn = (CImageView*)child;
			pBtn->setTouchEnabled(true);
			pBtn->setUserData(&m_headIconList.at(uIdx));
			pBtn->setOnClickListener(this,ccw_click_selector(CChangeHeadImg::onChangHeadImg));
		}
	}
}
Example #27
0
void GamePan::refreshWorldPad()
{
	CCNode* pBaseNode = m_pCcbNode->getChildByTag(kTagGamePanWordPan);
	CCNode* tabNode = pBaseNode->getChildByTag(kTagGamePanWordPanTabBase);
	CCNode* itemNode = pBaseNode->getChildByTag(kTagGamePanWordPanItemBase);
	CCLabelTTF* itemTemp = dynamic_cast<CCLabelTTF*>(itemNode->getChildByTag(kTagGamePanWordPanItemTitle));
	CCControlButton* tabItem = dynamic_cast<CCControlButton*>(tabNode->getChildByTag(kTagGamePanWordPanTabBaseItem));
	float itemWidth = tabItem->getContentSize().width+ITEM_SPACE;
	float itemHeight = tabItem->getContentSize().height+ITEM_SPACE;
	for(int i =0;i<MAX_LINE;i++)
	{
		for(int j =0;j<MAX_ROW;j++)
		{
			CCControlButton* item = CCControlButton::create();
			Utils::copyCCControlButton(item,tabItem);
			item->setPosition(ccp(tabItem->getPositionX()+j*itemWidth,tabItem->getPositionY()-i*itemHeight));
			item->setTag(j+i*MAX_ROW);
			tabNode->addChild(item);

			CCLabelTTF* title = Utils::copyCCLabelTTF(itemTemp);
			title->setPosition(item->getPosition());
			title->setTag(j+i*MAX_ROW);
			itemNode->addChild(title);
			CCString* str = (CCString*)_wordList->randomObject();
			title->setString(str->getCString());
			_wordList->removeObject(str);
		}
	}

	for(int i =0;i<MAX_LINE;i++)
	{
		for(int j =0;j<MAX_ROW;j++)
		{
			CCControlButton* item = dynamic_cast<CCControlButton*>(tabNode->getChildByTag(j+i*MAX_ROW));
			XCheckBox* pCheckBox = XCheckBox::create(item);
			pCheckBox->setTag(item->getTag());
			pCheckBox->setToggle(false);
			pCheckBox->setTarget(this, cccontrol_selector(GamePan::wordSelectCallbackCCControl));
			tabNode->addChild(pCheckBox);
			item->removeFromParent();
		}
	}
	itemTemp->removeFromParent();
	tabItem->removeFromParent();
	refreshLetter();
}
CCNode * CCBReader::readNodeGraph(CCNode * pParent) {
    /* Read class name. */
    CCString * className = this->readCachedString();

    int memberVarAssignmentType = this->readInt(false);
    CCString * memberVarAssignmentName;
    if(memberVarAssignmentType != kCCBTargetTypeNone) {
        memberVarAssignmentName = this->readCachedString();
    }

    CCNodeLoader * ccNodeLoader = this->mCCNodeLoaderLibrary->getCCNodeLoader(className);
    CCNode * node = ccNodeLoader->loadCCNode(pParent, this);

    /* Set root node, if not set yet. */
    if(this->mRootNode == NULL) {
        this->mRootNode = node;
        this->mRootNode->retain();
    }

    if(memberVarAssignmentType != kCCBTargetTypeNone) {
        CCObject * target = NULL;
        if(memberVarAssignmentType == kCCBTargetTypeDocumentRoot) {
            target = this->mRootNode;
        } else if(memberVarAssignmentType == kCCBTargetTypeOwner) {
            target = this->mOwner;
        }

        if(target != NULL) {
            bool assigned = false;

            CCBMemberVariableAssigner * targetAsCCBMemberVariableAssigner = dynamic_cast<CCBMemberVariableAssigner *>(target);

            if(targetAsCCBMemberVariableAssigner != NULL) {
                assigned = targetAsCCBMemberVariableAssigner->onAssignCCBMemberVariable(target, memberVarAssignmentName, node);
            }

            if(!assigned && this->mCCBMemberVariableAssigner != NULL) {
                this->mCCBMemberVariableAssigner->onAssignCCBMemberVariable(target, memberVarAssignmentName, node);
            }
        }
    }

    /* Read and add children. */
    int numChildren = this->readInt(false);
    for(int i = 0; i < numChildren; i++) {
        CCNode * child = this->readNodeGraph(node);
        node->addChild(child);
    }

    CCNodeLoaderListener * nodeAsCCNodeLoaderListener = dynamic_cast<CCNodeLoaderListener *>(node);
    if(nodeAsCCNodeLoaderListener != NULL) {
        nodeAsCCNodeLoaderListener->onNodeLoaded(node, ccNodeLoader);
    } else if(this->mCCNodeLoaderListener != NULL) {
        this->mCCNodeLoaderListener->onNodeLoaded(node, ccNodeLoader);
    }

    return node;
}
Example #29
0
void GamePan::addPlayer(DB_Actor* pActor)
{
	CCNode* pBaseNode = m_pCcbNode->getChildByTag(kTagGamePanSelf)->getChildByTag(0);
	pBaseNode->removeAllChildren();
	Player* player = Player::create();
	player->loadCCB(pBaseNode,("scene/actor/"+pActor->resource).c_str());
	pBaseNode->addChild(player);
	player->doOpen();
	player->setPosition(CCPointZero-(player->getContentSize()/2));
}
Example #30
0
void GamePan::addNpc(DB_Actor* pActor)
{
	CCNode* pBaseNode = m_pCcbNode->getChildByTag(kTagGamePanOpp)->getChildByTag(0);
	pBaseNode->removeAllChildren();
	Npc* npc = Npc::create();
	npc->loadCCB(pBaseNode,("scene/actor/"+pActor->resource).c_str());
	pBaseNode->addChild(npc);
	npc->doOpen();
	npc->setPosition(CCPointZero-(npc->getContentSize()/2));
}