本文整理汇总了C++中CCNode::getPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ CCNode::getPosition方法的具体用法?C++ CCNode::getPosition怎么用?C++ CCNode::getPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCNode
的用法示例。
在下文中一共展示了CCNode::getPosition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateWithVelocity
// Used with box2d style velocity (m/s where m = 32 pixels), but box2d is not required
void CCParallaxScrollNode::updateWithVelocity(CCPoint vel, float dt)
{
vel = ccpMult(vel, PTM_RATIO);
// CCLog("count: %i", _scrollOffsets->count());
CCObject* object;
CCARRAY_FOREACH(_scrollOffsets, object)
{
CCParallaxScrollOffset* scrollOffset = dynamic_cast<CCParallaxScrollOffset*>(object);
CCPoint relVel = ccpMult(scrollOffset->getRelVelocity(), PTM_RATIO);
CCPoint totalVel = ccpAdd(vel, relVel);
CCPoint offset = ccpCompMult(ccpMult(totalVel, dt), scrollOffset->getRatio());
CCNode *child = scrollOffset->getTheChild();
child->setPosition(ccpAdd(child->getPosition(), offset));
if ( (offset.x < 0 && child->getPosition().x + child->getContentSize().width < 0) ||
(offset.x > 0 && child->getPosition().x > _range.width) ) {
child->setPosition(ccpAdd(child->getPosition(), ccp(-SIGN(offset.x) * fabs(scrollOffset->getScrollOffset().x), 0)));
}
// Positive y indicates upward movement in cocos2d
if ( (offset.y < 0 && child->getPosition().y + child->getContentSize().height < 0) ||
(offset.y > 0 && child->getPosition().y > _range.height) ) {
child->setPosition(ccpAdd(child->getPosition(), ccp(0, -SIGN(offset.y) * fabs(scrollOffset->getScrollOffset().y))));
}
}
示例2: onEnter
//------------------------------------
//
//
void CShopLayer::onEnter()
{
CCXMLLayer::onEnter();
LoadPlist("gameshop.plist");
const char *MenuButton[] =
{
"button_back",
"button_1",
"button_2",
"button_3",
"button_4",
"button_91"
};
for( int i = 0; i < 6; i++ )
{
CCSprite *pSprite= (CCSprite*)GetXMLNodeFromKey( MenuButton[i] );
CCMenu *pMenu = CreatGameUIWithSprite( pSprite, menu_selector(CShopLayer::menuCallback), i, this, pSprite->getPosition() );
addChild( pMenu, pSprite->getZOrder() );
removeChild( pSprite, true );
}
CCNode *pNode = GetXMLNodeFromKey( "t2dSceneObject_money_1" );
char buffer[32];
sprintf( buffer, shop_1[g_iCurLanguageIndex], 1 );
string utf8;
CChineseCode::GB2312ToUTF_8( utf8, buffer, 256 );
CCLabelTTF *plabelName = CCLabelTTF::labelWithString(buffer, kFontSystem[FONT_MED].fontName,kFontSystem[FONT_MED].fontSize);
addChild(plabelName,99);
plabelName->setPosition( pNode->getPosition() );
pNode = GetXMLNodeFromKey( "t2dSceneObject_money_2" );
sprintf( buffer, shop_1[g_iCurLanguageIndex], 4 );
CChineseCode::GB2312ToUTF_8( utf8, buffer, 256 );
plabelName = CCLabelTTF::labelWithString(buffer, kFontSystem[FONT_MED].fontName,kFontSystem[FONT_MED].fontSize);
addChild(plabelName,99);
plabelName->setPosition( pNode->getPosition() );
}
示例3: updateWithVelocity
void CCParallaxScrollNode::updateWithVelocity(const CCPoint &vel, float dt) {
CCSize screen = CCDirector::sharedDirector()->getWinSize();
CCPoint vel2 = ccpMult(vel, PTM_RATIO);
for (int i=scrollOffsets->num - 1; i >= 0; i--) {
CCParallaxScrollOffset *scrollOffset = (CCParallaxScrollOffset*)scrollOffsets->arr[i];
CCNode *child = scrollOffset->getChild();
CCPoint relVel = ccpMult(scrollOffset->getRelVelocity(), PTM_RATIO);
CCPoint totalVel = ccpAdd(vel2, relVel);
CCPoint tmp = ccpMult(totalVel, dt);
CCPoint offset = ccpCompMult(tmp, scrollOffset->getRatio());
child->setPosition(ccpAdd(child->getPosition(), offset));
if ( (vel2.x < 0 && child->getPosition().x + child->getContentSize().width < 0) ||
(vel2.x > 0 && child->getPosition().x > screen.width) ) {
child->setPosition(ccpAdd(child->getPosition(), ccp(-SIGN(vel2.x) * fabs(scrollOffset->getScrollOffset().x), 0)));
}
// Positive y indicates upward movement in cocos2d
if ( (vel2.y < 0 && child->getPosition().y + child->getContentSize().height < 0) ||
(vel2.y > 0 && child->getPosition().y > screen.height) ) {
child->setPosition(ccpAdd(child->getPosition(), ccp(0, -SIGN(vel2.y) * fabs(scrollOffset->getScrollOffset().y))));
}
}
}
示例4: updateWithYPosition
void CCParallaxScrollNode::updateWithYPosition(float y, float dt)
{
for (int i=scrollOffsets->num - 1; i >= 0; i--) {
CCParallaxScrollOffset *scrollOffset = (CCParallaxScrollOffset*)scrollOffsets->arr[i];
CCNode *child = scrollOffset->getChild();
float offset = y * scrollOffset->getRatio().y;//ccpCompMult(pos, scrollOffset.ratio);
child->setPosition(ccp(child->getPosition().x, scrollOffset->getOrigPosition().y + offset));
}
}
示例5: animation
void CCounter::animation(int digit)
{
CCNode* presenter = _presenters->getChildByTag(digit);
CCPoint dest = presenter->getPosition();
// this->stopActionByTag(k_Counter_Action);
_presenters->stopAllActions();
CCMoveTo* moveTo = CCMoveTo::create(0.5, CCPointMake(0, -dest.y));
_presenters->runAction(moveTo);
}
示例6: ccTouchBegan
bool CCCGameScrollView::ccTouchBegan( CCTouch *pTouch, CCEvent *pEvent )
{
CCPoint touchPoint=pTouch->getLocation();
// 将世界坐标转换为当前父View的本地坐标系
CCPoint reallyPoint=this->getParent()->convertToNodeSpace(touchPoint);
//CCPoint touchPoint = this->convertTouchToNodeSpace(pTouch);
if (!this->boundingBox().containsPoint(reallyPoint)) {
return false;
}
m_BeginOffset = getContentOffset();
CCPoint m_EndOffset = getContentOffset();
//点击Page的功能
// if (m_BeginOffset.equals(m_EndOffset))
{
int nPage = -1;
if (m_eDirection == kCCScrollViewDirectionHorizontal)
{
nPage = abs(m_EndOffset.x / (int)m_CellSize.width);
}
else
{
nPage = abs(m_EndOffset.y / (int)m_CellSize.height);
}
CCCGameScrollViewDelegate *pDele = (CCCGameScrollViewDelegate *)m_pDelegate;
CCNode *pPgae = m_pContainer->getChildByTag(nPage);
CCRect rcContent;
rcContent.origin = pPgae->getPosition();
rcContent.size = pPgae->getContentSize();
// rcContent.origin.x -= rcContent.size.width / 2;
// rcContent.origin.y -= rcContent.size.height / 2;
CCPoint pos1 = this->convertTouchToNodeSpace(pTouch);
CCPoint pos =pos1;
if (m_eDirection == kCCScrollViewDirectionHorizontal)
{
pos.x += nPage * m_CellSize.width;
}
else
{
pos.y -= nPage * m_CellSize.height;
}
if (rcContent.containsPoint(pos))
{
pDele->scrollViewTouchBegan(pPgae,pos1);
}
}
return CCScrollView::ccTouchBegan(pTouch, pEvent);;
}
示例7: CCRect
KDvoid Ch1_1DEasingActions::step ( KDfloat fDelta )
{
CCNode* pBreadcrumbs = this->getChildByTag ( TAG_BREADCRUMBS );
CCNode* pNode = this->getChildByTag ( TAG_SPRITE_TO_MOVE );
CCSprite* pCrumb = CCSprite::create ( "blank.png" );
pCrumb->setTextureRect ( CCRect ( 0, 0, 2, 2 ) );
pCrumb->setColor ( ccc3 ( 255, 255, 0 ) );
pCrumb->setPosition ( pNode->getPosition ( ) );
pBreadcrumbs->addChild ( pCrumb );
}
示例8: 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;
}
示例9: setDigit
void CCounter::setDigit(int digit,bool bAnimate)
{
if(_digit != digit){
_digit = digit;
CCNode* presenter = _presenters->getChildByTag(digit);
CCPoint dest = presenter->getPosition();
if(bAnimate)
animation(digit);
else
_moveTo(digit,ccp(0, -dest.y));
}
}
示例10: update
void MainLayer::update(float delta)
{
if (!disappearing)
{
CCNode *left = this->getChildByTag(TAG_LEFT);
CCNode *right = this->getChildByTag(TAG_RIGHT);
if (left && right)
{
CCRect leftRect = left->boundingBox();
CCRect rightRect = right->boundingBox();
leftRect.size = leftRect.size * 0.85f;
rightRect.size = rightRect.size * 0.8f;
if (leftRect.intersectsRect(rightRect))
{
disappearing = true;
/*爆炸*/
playDropAnimation();
}
else if (left->getPosition().x > right->getPosition().x)
{
disappearing = true;
leftJumping = false;
rightJumping = false;
//计分
Counter *counter = Counter::sharedCounter();
(*counter)++;
this->reCreateNewRole();
// left->runAction(CCFadeOut::create(0.8f));
// right->runAction(
// CCSequence::createWithTwoActions(CCFadeOut::create(0.8f),
// CCCallFunc::create(this,
// callfunc_selector(
// MainLayer::reCreateNewRole))));
}
}
}
}
示例11: ccTouchEnded
void CCCGameScrollView::ccTouchEnded( CCTouch *pTouch, CCEvent *pEvent )
{
CCPoint touchPoint = this->convertTouchToNodeSpace(pTouch);
CCScrollView::ccTouchEnded(pTouch, pEvent);
CCPoint m_EndOffset = getContentOffset();
//点击Page的功能
if (m_BeginOffset.equals(m_EndOffset))
{
int nPage = -1;
if (m_eDirection == kCCScrollViewDirectionHorizontal)
{
nPage = abs(m_EndOffset.x / (int)m_CellSize.width);
}
else
{
nPage = abs(m_EndOffset.y / (int)m_CellSize.height);
}
CCCGameScrollViewDelegate *pDele = (CCCGameScrollViewDelegate *)m_pDelegate;
CCNode *pPgae = m_pContainer->getChildByTag(nPage);
CCRect rcContent;
rcContent.origin = pPgae->getPosition();
rcContent.size = pPgae->getContentSize();
// rcContent.origin.x -= rcContent.size.width / 2;
// rcContent.origin.y -= rcContent.size.height / 2;
CCPoint pos = touchPoint;
if (m_eDirection == kCCScrollViewDirectionHorizontal)
{
pos.x += nPage * m_CellSize.width;
}
else
{
pos.y -= nPage * m_CellSize.height;
}
if (rcContent.containsPoint(pos))
{
pDele->scrollViewClick(m_EndOffset, touchPoint, pPgae, nPage);
pDele->scrollViewTouchEnded(this,touchPoint);
}
return ;
}
//自动调整
adjustScrollView(m_BeginOffset, m_EndOffset);
}
示例12: 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) );
}
示例13: 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);
}
}
}
}
示例14: update
void MainMenu::update(float dt)
{
CCLayer::update(dt);
CCPoint bgVel = ccp(-1000,0);
bgSpace->setPosition( ccpAdd(bgSpace->getPosition(), ccpMult(bgVel,dt)) );
CCArray* bgs = CCArray::create(stars1,stars2,NULL);
CCObject* obj = NULL;
CCARRAY_FOREACH(bgs,obj)
{
CCNode* node = (CCNode*)obj;
if(bgSpace->convertToWorldSpace(node->getPosition()).x < -node->getContentSize().width/2)
{
bgSpace->incrementOffset(ccp(2*node->getContentSize().width,0),node);
}
}
示例15: Scroll
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 );
}