当前位置: 首页>>代码示例>>C++>>正文


C++ CCNode::setPosition方法代码示例

本文整理汇总了C++中CCNode::setPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ CCNode::setPosition方法的具体用法?C++ CCNode::setPosition怎么用?C++ CCNode::setPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CCNode的用法示例。


在下文中一共展示了CCNode::setPosition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: init

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;
}
开发者ID:beforeeight,项目名称:bump,代码行数:55,代码来源:MainLayer.cpp

示例2: ccp

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 ];
}
开发者ID:mcodegeeks,项目名称:OpenKODE-Framework,代码行数:42,代码来源:Ch1_1DEasingActions.cpp

示例3: ccTouchesMoved

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;
}
开发者ID:1901,项目名称:cocos2d-x,代码行数:11,代码来源:ClippingNodeTest.cpp

示例4: onEnter

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()) );
}
开发者ID:charlesa101,项目名称:cocos2d-x,代码行数:41,代码来源:RotateWorldTest.cpp

示例5:

//-------------------------------------------------------------------------
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 ) ); 
}
开发者ID:duzhi5368,项目名称:FKCocos2dxWrapper_2.x,代码行数:13,代码来源:Cocos2dxDisplayBridge.cpp

示例6: addRewardsNodeByIndex

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);
}
开发者ID:ourgames,项目名称:dc208,代码行数:52,代码来源:LotteryRotateView.cpp

示例7: init

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;
}
开发者ID:JimiWasBornIn1988,项目名称:FishingJoy,代码行数:13,代码来源:Counter.cpp

示例8: moveOutTouchUICompent

// 层移出
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("国战地图层 从主场景移除");
}
开发者ID:qjsy,项目名称:QjGit,代码行数:14,代码来源:GuoZhanLayer.cpp

示例9: FlashContext

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);
}
开发者ID:HaiWenShiZhu,项目名称:flash,代码行数:14,代码来源:FlashManager.cpp

示例10: playEffect

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;	
}
开发者ID:niuzb,项目名称:hellopetclient,代码行数:50,代码来源:SpriteMonsterArcher.cpp

示例11: update

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);
            }
        }
    }
}
开发者ID:rockingdice,项目名称:IceCreamJam,代码行数:14,代码来源:GUISpinView.cpp

示例12: handleCollisionWith

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();
    }
}
开发者ID:betallcoffee,项目名称:CocosXDragon,代码行数:14,代码来源:Bomb.cpp

示例13: Shop_FlyIn

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;
	}
	
}
开发者ID:wanggan768q,项目名称:GameWork,代码行数:14,代码来源:HSGameShopLayer.cpp

示例14: ccTouchMoved

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) );
}
开发者ID:YarinYang,项目名称:cocos2dx-win8,代码行数:14,代码来源:Box2dView.cpp

示例15: createContainer

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;
}
开发者ID:9cat,项目名称:dotawar,代码行数:37,代码来源:CCGameScrollView.cpp


注:本文中的CCNode::setPosition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。