本文整理汇总了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;
}
示例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 ];
}
示例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;
}
示例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()) );
}
示例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 ) );
}
示例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);
}
示例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;
}
示例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("国战地图层 从主场景移除");
}
示例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);
}
示例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;
}
示例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);
}
}
}
}
示例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();
}
}
示例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;
}
}
示例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) );
}
示例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;
}