Example #1
0
bool MainLayer::init()
{
	/*-- 设置整体层属性 --*/
	this->setTouchMode(kCCTouchesOneByOne);
	this->setTouchEnabled(true);
	this->scheduleUpdate();
	CCSize s = CCDirector::sharedDirector()->getWinSize();
	this->ignoreAnchorPointForPosition(true);
	setAnchorPoint(ccp(0.5f, 0.5f));
	this->setContentSize(s);
	setPosition(ccp(s.width / 2, s.height / 2));

	CCSize vsize = CCDirector::sharedDirector()->getVisibleSize();
	float width = vsize.width / 2;
	float height = vsize.height / 2;
	Counter *counter = Counter::sharedCounter();
	counter->clearScore();
	if (counter->isSound()
			&& !SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying())
	{
		SimpleAudioEngine::sharedEngine()->playBackgroundMusic("bgm.mp3", true);
	}
	/*-- door --*/
	CCAnimation *doorAnimation =
			CCAnimationCache::sharedAnimationCache()->animationByName("door");
	//左侧
	CCSprite *leftDoor = CCSprite::createWithSpriteFrameName("door_1.png");
	leftDoor->setPosition(ccp(-200, -50));
	leftDoor->setAnchorPoint(ccp(0.5, 0.5));
	this->addChild(leftDoor);
	leftDoor->runAction(
			CCRepeatForever::create(CCAnimate::create(doorAnimation)));

	//右侧
	CCSprite *rightDoor = CCSprite::createWithSpriteFrameName("door_1.png");
	rightDoor->setPosition(ccp(200, -50));
	rightDoor->setAnchorPoint(ccp(0.5, 0.5));
	this->addChild(rightDoor);
	rightDoor->runAction(
			CCRepeatForever::create(CCAnimate::create(doorAnimation)));

	/*-- 分数 --*/
	CCLabelTTF *titletxt = CCLabelTTF::create(counter->getStringByKey("score"),
			counter->getStringByKey("font"), 46);
	titletxt->setColor(ccc3(98, 104, 191));
	titletxt->setAnchorPoint(ccp(0.5, 0.5));
	titletxt->setPosition(ccp(0, height - 130));
	this->addChild(titletxt);
	CCNode *scoreLabel = counter->create_label();
	scoreLabel->setPosition(ccp(0, height - 200));
	scoreLabel->setAnchorPoint(ccp(0.5, 1));
	this->addChild(scoreLabel, 3, TAG_SCORE);
	/*-- role --*/
	return true;
}
const KDchar* Ch1_1DEasingActions::runSubAction ( KDint nIndex )
{
	// Clean and re-add breadcrumbs
	CCNode*		pBreadcrumbs = this->getChildByTag ( TAG_BREADCRUMBS );
	this->removeChild ( pBreadcrumbs );

	pBreadcrumbs = CCSprite::create ( "blank.png" );
	pBreadcrumbs->setPosition ( ccp ( 0, 0 ) );
	this->addChild ( pBreadcrumbs, 0, TAG_BREADCRUMBS );

	CCNode*		pNode = this->getChildByTag ( TAG_SPRITE_TO_MOVE );
	pNode->stopAllActions ( );
	pNode->setPosition ( ccp ( 150, 50 ) );

	CCActionInterval*	pEaseAction = KD_NULL;

	switch ( nIndex )
	{
		case  0 :	pEaseAction = CCEaseIn					::create ( m_pActionToEase, 2 );	break;
		case  1 :	pEaseAction = CCEaseOut					::create ( m_pActionToEase, 2 );	break;
		case  2 :	pEaseAction = CCEaseInOut				::create ( m_pActionToEase, 2 );	break;
		case  3 :	pEaseAction = CCEaseExponentialIn		::create ( m_pActionToEase );		break;
		case  4 :	pEaseAction = CCEaseExponentialOut		::create ( m_pActionToEase );		break;
		case  5 :	pEaseAction = CCEaseExponentialInOut	::create ( m_pActionToEase );		break;
		case  6 :	pEaseAction = CCEaseSineIn				::create ( m_pActionToEase );		break;
		case  7 :	pEaseAction = CCEaseSineOut				::create ( m_pActionToEase );		break;
		case  8 :	pEaseAction = CCEaseSineInOut			::create ( m_pActionToEase );		break;
		case  9 :	pEaseAction = CCEaseElasticIn			::create ( m_pActionToEase, 0.3f );	break;
		case 10 :	pEaseAction = CCEaseElasticOut			::create ( m_pActionToEase, 0.3f );	break;
		case 11 :	pEaseAction = CCEaseElasticInOut		::create ( m_pActionToEase, 0.3f );	break;
		case 12 :	pEaseAction = CCEaseBounceIn			::create ( m_pActionToEase );		break;
		case 13 :	pEaseAction = CCEaseBounceOut			::create ( m_pActionToEase );		break;
		case 14 :	pEaseAction = CCEaseBounceInOut			::create ( m_pActionToEase );		break;
		case 15 :	pEaseAction = CCEaseBackIn				::create ( m_pActionToEase );		break;
		case 16 :	pEaseAction = CCEaseBackOut				::create ( m_pActionToEase );		break;
		case 17 :	pEaseAction = CCEaseBackInOut			::create ( m_pActionToEase );		break;
	}

	pNode->runAction ( pEaseAction );

	return l_aActionMethods [ nIndex ];
}
Example #3
0
void ScrollViewDemo::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent)
{
    if (!m_bScrolling) return;
	CCTouch *touch = (CCTouch*)pTouches->anyObject();
    CCNode *clipper = this->getChildByTag(kTagClipperNode);
    CCPoint point = clipper->convertToNodeSpace(CCDirector::sharedDirector()->convertToGL(touch->getLocationInView()));
	CCPoint diff = ccpSub(point, m_lastPoint);
    CCNode *content = clipper->getChildByTag(kTagContentNode);
    content->setPosition( ccpAdd(content->getPosition(), diff) );
    m_lastPoint = point;
}
void RotateWorldMainLayer::onEnter()
{
	CCLayer::onEnter();

	float x,y;
	
	CGSize size = CCDirector::sharedDirector()->getWinSize();
	x = size.width;
	y = size.height;
	
	CCNode* blue =  CCColorLayer::layerWithColor(ccc4(0,0,255,255));
	CCNode* red =   CCColorLayer::layerWithColor(ccc4(255,0,0,255));
	CCNode* green = CCColorLayer::layerWithColor(ccc4(0,255,0,255));
	CCNode* white = CCColorLayer::layerWithColor(ccc4(255,255,255,255));

	blue->setScale(0.5f);
	blue->setPosition(CGPointMake(-x/4,-y/4));
	blue->addChild( SpriteLayer::node() );
	
	red->setScale(0.5f);
	red->setPosition(CGPointMake(x/4,-y/4));

	green->setScale(0.5f);
	green->setPosition(CGPointMake(-x/4,y/4));
	green->addChild(TestLayer::node());

	white->setScale(0.5f);
	white->setPosition(CGPointMake(x/4,y/4));

	addChild(blue, -1);
	addChild(white);
	addChild(green);
	addChild(red);

	CCAction* rot = CCRotateBy::actionWithDuration(8, 720);
	
	blue->runAction(rot);
	red->runAction((CCAction *)(rot->copy()->autorelease()));
	green->runAction((CCAction *)(rot->copy()->autorelease()) );
	white->runAction((CCAction *)(rot->copy()->autorelease()) );
}
//-------------------------------------------------------------------------
void CCocos2dxDBDisplayBridge::UpdateTransform( CMatrix& p_Matrix, CTransform& p_Transform )
{
	if( m_pDisplayNode == NULL )
		return;

	CCNode* pNode = m_pDisplayNode->GetNode();
	pNode->setPosition( p_Matrix.m_fX, -p_Matrix.m_fY );
	pNode->setScaleX( p_Transform.m_fScaleX );
	pNode->setScaleY( p_Transform.m_fScaleY );
	pNode->setRotationX( CC_RADIANS_TO_DEGREES( p_Transform.m_fSkewX ) );
	pNode->setRotationY( CC_RADIANS_TO_DEGREES( p_Transform.m_fSkewY ) ); 
}
Example #6
0
void LotteryRotateView::addRewardsNodeByIndex(int idx){
    
    nodeParticleIdx = idx;
    string iconStr = "";
    
    CCDictionary* dict = dynamic_cast<CCDictionary*>(m_save10Arr->objectAtIndex(idx));
    int dictType = dict->valueForKey("type")->intValue();
    CCDictionary* rewardsDic = _dict(dict->objectForKey("result"));
    if (dictType == 0) {//RESOURCE
        int resType = rewardsDic->valueForKey("type")->intValue();
        iconStr = LotteryController::shared()->getIcon(resType);
    }else if (dictType == 1){//BOX_TIMES
        iconStr = LotteryController::shared()->getIcon(100);
    }else if (dictType == 2){//REWARD
        int resType = rewardsDic->valueForKey("type")->intValue();
        if (resType == 7) {
            CCDictionary* valueDic = _dict(rewardsDic->objectForKey("value"));
            int itemId = valueDic->valueForKey("itemId")->intValue();
            iconStr = CCCommonUtils::getIcon(CC_ITOA(itemId));
        }else{
            iconStr = LotteryController::shared()->getIcon(resType);
        }
    }
    
    auto rewardIcon =CCLoadSprite::createSprite(iconStr.c_str());
    CCCommonUtils::setSpriteMaxSize(rewardIcon, 80);
    if (nodeParticleIdx<5) {
        rewardIcon->setPosition((100*nodeParticleIdx)-200, 45);
    }else{
        rewardIcon->setPosition((100*(nodeParticleIdx-5))-200, -45);
    }
    rewardIcon->setOpacity(0.5);
    CCActionInterval *fadeIn = CCFadeIn::create(0.3);
    rewardIcon->setScale(0.8);
    CCActionInterval *scale1 = CCScaleTo::create(0.1, 1.2);
    CCActionInterval *scale2 = CCScaleTo::create(0.1, 1.0);
    //粒子特效
    CCNode *pNode = CCNode::create();
    pNode->setPosition(rewardIcon->getPosition());
    m_rewardsContainer->addChild(pNode);
    auto func =CCCallFuncO::create(this, callfuncO_selector(LotteryRotateView::addRewardsNodeParticle),pNode);
    rewardIcon->runAction(CCSequence::create(fadeIn,scale1,scale2,func, NULL));
    
    m_rewardsContainer->addChild(rewardIcon);
    
//    string m_itemId="200380";
//    int id = atoi(m_itemId.c_str());
//    CCCommonUtils::flyHintWithDefault("Lottery_wood.png", "", _lang_1("104913", LotteryController::shared()->getLotteryName(id, 100).c_str()),0.5);
    //飘字特效
//    ccColor3B textColor = TEXT_COLOR_YELLOW;
//    CCCommonUtils::flyUiResText("Lottery_wood.png", m_rewardsContainer,ccp(0, 0) ,textColor, floating_type_ui1, 23);
}
Example #7
0
bool Counter::init(CCArray* presenters, int digit)
{
	_presenters = CCNode::create();
	for (int i = 0; i < 10; i++) {
		CCNode* node = (CCNode*)presenters->objectAtIndex(i);
		int y = node->getContentSize().height*i;
		node->setPosition(CCPointMake(0, y));
		_presenters->addChild(node, 0, i);
	}
	this->addChild(_presenters);
	this->setDigit(digit);
	return true;
}
Example #8
0
// 层移出
void GuoZhanLayer::moveOutTouchUICompent(){
    CCSprite* parent = static_cast<CCSprite*>(m_pSBN->getChildByTag(GUOZ_BG_TAG));
    parent->setPosition(INIT_LAYER_POSITION);
    CCNode* pNode = (CCNode*)this->getChildByTag(NODE_TAG);
    pNode->setPosition(INIT_LAYER_POSITION);
    
    /*当前为PVE状态*/
    m_pBattle->setBattlePkMode(BPM_PVE);
    CCNotificationCenter::sharedNotificationCenter()->postNotification(ON_MESSAGE_MOVEGOBATTLE_STRING);
    
    this->removeFromParent();
    CCLog("国战地图层 从主场景移除");
}
Example #9
0
FlashInstance::FlashInstance(Flash* flash, Sequence* seq) {
    flash->referInstance();
    this->flash = flash;
	this->framerate = flash->framerate;
	this->sequence = seq;
    this->context = new FlashContext();

	this->node = CCNode::create();
	node->retain();
	node->setContentSize(CCSize(flash->width, flash->height));
	CCNode* cnode = seq->getNode();
	cnode->setPosition(CCPoint(0, flash->height));
	node->addChild(cnode);
}
void SpriteMonsterArcher::playEffect(SkillInfo info)
{		
	initEffect(info.effectId);
	
	CCNode * effectNode = getFreeEffectNode();
	if (!effectNode)
	{
		return;
	}

	float distance = ccpDistance(info.startPosition, info.endPosition);
	float speed = info.speed * 16;
	CCPoint directVec = ccpSub(info.endPosition, info.startPosition);

	float degree;
	degree = atan(directVec.x / directVec.y) * 180 / 3.14;
	if (directVec.y < 0)
	{
		degree += 180;
	}

	CCPoint startCell = LevelManager::sShareInstance()->pointPixelToCell(info.startPosition);
	CCPoint endCell = LevelManager::sShareInstance()->pointPixelToCell(info.endPosition);
	//CCLOG("arrow start pos: %f, %f, end pos: %f, %f", startCell.x, startCell.y, endCell.x, endCell.y);

	effectNode->setPosition(info.startPosition);	
	effectNode->setRotation(degree);	
	
	CCArray *arrayOfActions = CCArray::create();

	CCDelayTime * delayEffect = CCDelayTime::create(info.delayTime / 1000);
	CCCallFunc *showFunc = CCCallFuncND::create(this, 
										callfuncND_selector(SpriteMonster::ccCallShowEffect),
										(void *)effectNode);
	CCMoveTo * moveEffect = CCMoveTo::create(distance / speed, info.endPosition);	
	CCCallFunc *hideFunc = CCCallFuncND::create(this, 
										callfuncND_selector(SpriteMonster::ccCallHideEffect),
										(void *)effectNode);

	arrayOfActions->addObject(delayEffect);
	arrayOfActions->addObject(showFunc);
	arrayOfActions->addObject(moveEffect);
	arrayOfActions->addObject(hideFunc);
	CCFiniteTimeAction *sequence = CCSequence::create(arrayOfActions);

	effectNode->stopAllActions();
	effectNode->runAction(sequence);

	return;	
}
Example #11
0
void GUISpinView::update(float delta)
{
    CCArray * array = m_mainNode->getChildren();
    if (array) {
        for (int i = 0; i < array->count(); i++) {
            CCNode * node = (CCNode *)array->objectAtIndex(i);
            CCPoint p = node->getPosition();
            if (p.y + m_itemHeight * 0.5f < - m_viewFrame.size.height * 0.5f) {
                p.y += m_itemCount * m_itemHeight;
                node->setPosition(p);
            }
        }
    }
}
Example #12
0
void Bomb::handleCollisionWith(GameObject *gameObject)
{
    if (dynamic_cast<Dragon*>(gameObject)) {
        // Collided with the dragon, remove object and add an explosion instead.
        this->setIsScheduledForRemove(true);
        
        CCNodeLoaderLibrary* ccNodeLoaderLibrary = CCNodeLoaderLibrary::sharedCCNodeLoaderLibrary();
        CCBReader* ccbReader = new CCBReader(ccNodeLoaderLibrary);
        CCNode* pExplosion = ccbReader->readNodeGraphFromFile("Explosion.ccbi");
        pExplosion->setPosition(this->getPosition());
        this->getParent()->addChild(pExplosion);
        ccbReader->release();
    }
}
Example #13
0
void HSGameShopLayer::Shop_FlyIn( CCNode& shop_frame,CCPoint&frame_Position)
{
	if(!m_shop_flyIn)
	{
		shop_frame.setPosition(ccp(frame_Position.x,-frame_Position.y));

		CCActionInterval* actionFlyIn =CCMoveTo::create(0.3f,frame_Position);
		CCCallFunc* pCallFunc = CCCallFunc::create(this,callfunc_selector(HSGameShopLayer::Shop_FlyInFinish));
		shop_frame.runAction(CCSequence::create(actionFlyIn,pCallFunc,NULL));

		m_shop_flyIn = true;
	}
	
}
Example #14
0
void MenuLayer::ccTouchMoved(CCTouch* touch, CCEvent* event)
{
	CCPoint touchLocation = touch->locationInView( touch->view() );	
	CCPoint prevLocation = touch->previousLocationInView( touch->view() );	
	
	touchLocation = CCDirector::sharedDirector()->convertToGL( touchLocation );
	prevLocation = CCDirector::sharedDirector()->convertToGL( prevLocation );
	
	CCPoint diff = ccpSub(touchLocation,prevLocation);
	
	CCNode *node = getChildByTag( kTagBox2DNode );
	CCPoint currentPos = node->getPosition();
	node->setPosition( ccpAdd(currentPos, diff) );
}
Example #15
0
bool CCCGameScrollView::createContainer(CCCGameScrollViewDelegate *pDele, int nCount, const cocos2d::CCSize &oSize )
{
	CCAssert(m_bSetDirection, "must call setDirection first!!!");
	m_nPageCount = nCount;
	m_CellSize = oSize;
	setDelegate(pDele);
    if (nCount==1) {
        
    }
	CCLayer *pContainer = CCLayer::create();

	CCSize winSize =CCSizeZero ; //CCDirector::sharedDirector()->getVisibleSize();
	for (int i = 0; i < nCount; ++i)
	{
		CCNode *pNode = CCNode::create();
        pNode->setAnchorPoint(ccp(0, 0));
		pDele->scrollViewInitPage(this, pNode, i);

		if (m_eDirection == kCCScrollViewDirectionHorizontal)
		{
			pNode->setPosition(ccp( i * oSize.width, 0));
		}
		else
		{
			pNode->setPosition(ccp(0,i * oSize.height));
		}

		pNode->setContentSize(m_CellSize);
		pNode->setTag(i);
		pContainer->addChild(pNode);
	}
    
    setViewSize(m_CellSize);
	setContainer(pContainer);
     
	return true;
}
Example #16
0
    void CameraObserver::OnNotifyChange(INotifier *notify, const INotifyEvent *event)
    {
        if (NULL == event)
        {
            return;
        }
        switch (event->GetNotifyEventType())
        {
            case ENCameraEvent::enPosChanged:
                {
                    const CameraPosChanged *posChangedEvent = reinterpret_cast<const CameraPosChanged*>(event);
                    //setPosition(cocos2d::ccpNeg(posChangedEvent->GetCameraPosition()));
					cocos2d::CCPoint newPos = cocos2d::ccpNeg(posChangedEvent->GetCameraPosition());
					cocos2d::CCPoint dis = cocos2d::ccpSub(newPos, m_lastPos);
					if ( m_pChildren && m_pChildren->count() > 0 )
					{
						CCObject* child;
						CCARRAY_FOREACH(m_pChildren, child)
						{
							CCNode* pNode = (CCNode*)child;
							if (pNode)
							{
								MoveScale::iterator it = m_moveScale.find(pNode);
								if (m_moveScale.end() == it)
								{
									pNode->setPosition(newPos);
								}
								else
								{
									pNode->setPosition(ccpAdd(pNode->getPosition(), ccpMult(dis, it->second)));
								}
							}
						}
					}
					m_lastPos = cocos2d::ccpNeg(posChangedEvent->GetCameraPosition());
                }
Example #17
0
void GUISpinView::refresh()
{
    m_mainNode->removeAllChildren();
    m_itemCount = m_delegate->itemsCountForSpinView(this);
    for (int i = 0; i < m_itemCount; i++) {
        CCNode * node = m_delegate->createItemForSpinView(this, i);
        m_mainNode->addChild(node, 0, i);
        node->setAnchorPoint(ccp(0, 0.5f));
        CCPoint p = ccp(0, - m_itemHeight * i);
        if (p.y + m_itemHeight * 0.5f < - m_viewFrame.size.height * 0.5f) {
            p.y = m_itemHeight * (m_itemCount - i);
        }
        node->setPosition(p);
    }
}
Example #18
0
void CS_DISPLAY_NODE_UPDATE(Bone *bone, DecorativeDisplay *decoDisplay, float dt, bool dirty)
{    
    CCNode *displayNode = (CCNode*)decoDisplay->getDisplay();

    Node node;
    TransformHelp::matrixToNode(bone->nodeToArmatureTransform(), node);
    displayNode->setPosition(node.x, node.y);
    displayNode->setScaleX(node.scaleX);
    displayNode->setScaleY(node.scaleY);
    displayNode->setRotation(CC_RADIANS_TO_DEGREES(node.skewX));
    
//    displayNode->updateTransform();
    
    displayNode->update(dt);
}
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 #20
0
void BaseLevelBuilder::createMonsterBornPoints()
{
	vector<CCPoint> points = InstanceManager::Get()->getMonsterBornPoints();
	for (size_t i = 0; i < points.size(); i++)
	{
		EffectSprite* monsterBornPoint = ParticleManager::Get()->createEffectSprite(205,"");
		monsterBornPoint->SetAnim(kType_Play,1,true);

		CCNode * bornNode = CCNode::create();
		bornNode->addChild(monsterBornPoint);
		bornNode->setPosition(points[i]);

		m_level->addChild(bornNode, MAP_Z_TILE_BACKGROUND);		
	}	
	InstanceManager::Get()->clearMonsterBornPoints();
}
Example #21
0
bool CPKDlg::init()
{
    CCLayer::init();
    m_pLeftPhoto = m_pRightPhoto = NULL ;
    m_pDelegate = NULL ;
    
    CCNodeLoaderLibrary* plib = CCNodeLoaderLibrary::sharedCCNodeLoaderLibrary();
    CCBReader* pReader = new CCBReader(plib);
    CCNode* pnode =  pReader->readNodeGraphFromFile("PkDlg.ccbi",this);
    pnode->setPosition(ccpMult(ccpFromSize(getContentSize()), 0.5)) ;
    addChild(pnode) ;
    m_pAnimate = pReader->getAnimationManager() ;
    m_pAnimate->setDelegate(this);
    pReader->autorelease() ;
    return true ;
}
Example #22
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) ;
}
void ParallaxBackground::Scroll(CCTouch* touch)
{
    CCPoint diff = touch->getDelta();

    CCNode* node = getChildByTag(0);
    CCPoint currentPos = node->getPosition();
    float xpos = currentPos.x + diff.x;
    float ypos = currentPos.y/* + diff.y*/;

    ypos = std::max(ypos, -35.f);
    ypos = std::min(ypos, 35.f);

    xpos = std::max(xpos, -50.f);
    xpos = std::min(xpos, 50.f);

    node->setPosition(xpos , ypos );
}
Example #24
0
CCObject *HTouchEnabledLayerColor::dismissAllNodesEx(int command, CCObject *param) {
    HBakNodeInfo *info = NULL;
    for (int i = m_pBakNodeList->count() - 1; i >= 0; --i) {
        info = (HBakNodeInfo *)m_pBakNodeList->objectAtIndex(i);
        CCNode *node = info->m_pNode;
        node->retain();
        node->removeFromParentAndCleanup(false);
        info->m_pParent->addChild(node, info->m_iIndex);
        node->setScaleX(info->m_fScaleX);
        node->setScaleY(info->m_fScaleY);
        node->setPosition(info->m_ptPos);
        node->release();
        restoreAllPriorities(info);
    }
    m_pBakNodeList->removeAllObjects();
    return NULL;
}
Example #25
0
/**
*   键盘将要出现的时候
*/
void LoginView::keyboardWillShow(CCIMEKeyboardNotificationInfo& info)
{
    CCLog("LoginView:keyboardWillShowAt(origin:%f,%f, size:%f,%f)",
        info.end.origin.x, info.end.origin.y, info.end.size.width, info.end.size.height);

    if (! this->mTrackNodeArray)
    {
        return;
    }

    CCNode* trackNode = NULL ;
    CCRect rectTracked ;
    for(int i=0; i<this->mTrackNodeArray->count(); i++) 
    {
        trackNode = (CCNode*) this->mTrackNodeArray->objectAtIndex(i) ;

        rectTracked = getRect(trackNode);
        CCLog("LoginView:trackingNodeAt(origin:%f,%f, size:%f,%f)",
            rectTracked.origin.x, rectTracked.origin.y, rectTracked.size.width, rectTracked.size.height);

        // if the keyboard area doesn't intersect with the tracking node area, nothing need to do.
        if (! CCRect::CCRectIntersectsRect(rectTracked, info.end))
        {
            continue ;
        }

        // assume keyboard at the bottom of screen, calculate the vertical adjustment.
        float adjustVert = info.end.getMaxY() - rectTracked.getMinY();
        CCLog("LoginView:needAdjustVerticalPosition(%f)", adjustVert);

        // move all the children node of KeyboardNotificationLayer
        CCArray* children = getChildren();
        CCNode* node = 0;
        int count = children->count();
        CCPoint pos;
        for (int i = 0; i < count; ++i)
        {
            node = (CCNode*)children->objectAtIndex(i);
            pos = node->getPosition();
            pos.y += adjustVert;
            node->setPosition(pos);
        }
    }

    
}
Example #26
0
CCTableViewCell* ListViewLayer::tableCellAtIndex(CCTableView *table, unsigned int idx)
{
	CCTableViewCell *cell = table->dequeueCell();
	if (cell == NULL) {
		cell = new CCTableViewCell();
		cell->autorelease();

		if (mSource.creator)
		{
			CCNode* item = mSource.creator->getItemContentByIndex(idx);

			// 包裹
			CCNode* wraped = CCNode::create();
			wraped->setContentSize(item->getContentSize());
			wraped->addChild(item,0);

			// 有个0.5,0.5的偏移
			wraped->setPosition(ccp(wraped->getContentSize().width/2,wraped->getContentSize().height/2));

			cell->addChild(wraped,0,TAG_LIST_CELL_ITEM_WRAP);
		}else
		{
			CCAssert(false,"");
		}

		CCLog("ListViewLayer::tableCellAtIndex ---> create!");
	}
	else
	{
		CCLog("ListViewLayer::tableCellAtIndex ---> refesh!");

		CCNode* warped = cell->getChildByTag(TAG_LIST_CELL_ITEM_WRAP);
		CCNode* item = (CCNode*)warped->getChildren()->objectAtIndex(0);

		if (mSource.creator)
		{
			mSource.creator->refreshItem(item,idx);
		}else
		{
			CCAssert(false,"");
		}
	}

	return cell;
}
void EquipmentUpgradeUILayer::playUpgradeEffect()
{
	if(m_choosedEquipmentPic && m_choosedEquipmentPic->getCurrentNode())
	{
		CCNode* particle = ParticleManagerX::sharedManager()->getParticles_uieffect("particle_effect_upgradesuccess");
		if(particle != NULL)
		{
			CCNode* child = m_choosedEquipmentPic->getCurrentNode()->getChildByTag(100);
			if(child)
			{
				child->removeFromParentAndCleanup(true);
				child = NULL;
			}
			m_choosedEquipmentPic->getCurrentNode()->addChild(particle,100,100);
			particle->setPosition(ccp(m_choosedEquipmentPic->getCurrentNode()->getContentSize().width * 0.5,m_choosedEquipmentPic->getCurrentNode()->getContentSize().height * 0.5));
		}
	}
}
void PlanPlayer:: planMoveTo(CCPoint after){
	//对于after 移动到的目的地进行边界判断
	CCNode * node = getChildByTag(AIR_PLAN_TAG);
	CCSize s = CCDirector::sharedDirector()->getWinSize();
	if(after.y >= s.height/2.0f - node->getContentSize().height){
		after.y = s.height/2.0f - node->getContentSize().height;
	}else if(after.y<= node->getContentSize().height/2.0f+50){
		after.y = node->getContentSize().height/2.0f+50;
	}

	if(after.x>=s.width - node->getContentSize().width/2.0f){
		after.x = s.width - node->getContentSize().width/2.0f;
	}else if(after.x <= node->getContentSize().width/2.0f){
		after.x = node->getContentSize().width/2.0f;
	}
	
	node->setPosition(after);
}
Example #29
0
bool CCounter::init(CCArray* presenters, int digit)
{
    _presenters = CCNode::create();
    for (int i = 0; i < 10; i++) {
        CCNode* node = (CCNode*)presenters->objectAtIndex(i);
        int y = node->getContentSize().height*i;
		if (i > 0)
		{
			CCNode* pPreNode = (CCNode*)presenters->objectAtIndex(i - 1);
			y = pPreNode->getPositionY() + pPreNode->getContentSize().height/2 + node->getContentSize().height/2 + 2;
		}
        node->setPosition(CCPointMake(0, y));
        _presenters->addChild(node, 0, i);
    }
    this->addChild(_presenters,0,k_Counter_Action);
    this->setDigit(digit,false);
    return true;
}
Example #30
0
void LCCrossMatchGame::shuffleNodes(CCArray* nodeArray)
{
	CCArray *tempArray = CCArray::arrayWithArray(nodeArray);
	CCPoint *tempPosition = (CCPoint *)malloc(sizeof(CCPoint) * nodeArray->count());
	
	for (int i=0; i<nodeArray->count(); i++) {
		CCNode* node = (CCNode*)tempArray->randomObject();
		tempArray->removeObject(node);
		
		tempPosition[i] = node->getPosition();
	}
	
	for (int i=0; i<nodeArray->count(); i++) {
		CCNode* node = (CCNode*)nodeArray->objectAtIndex(i);
		node->setPosition(tempPosition[i]);
	}
	
	free(tempPosition);
}