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


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

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


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

示例1: 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))));
            }
        }
    }
开发者ID:seenu19,项目名称:CCParallaxScrollNode,代码行数:30,代码来源:CCParallaxScrollNode.cpp

示例2: relayoutAsHorizontal

void HRootLayer::relayoutAsHorizontal(CCArray *nodes, CCPoint basePos, int interval) {
    for (int i = 0; i < nodes->count(); ++i) {
        CCNode *node = (CCNode *)nodes->objectAtIndex(i);
        node->setPosition(CCPointMake(basePos.x + node->getAnchorPoint().x * node->getContentSize().width * node->getScaleX(), basePos.y));
        basePos.x += node->getContentSize().width * node->getScaleX() + interval;
    }
}
开发者ID:hyizsg,项目名称:mytest1st,代码行数:7,代码来源:RootLayer.cpp

示例3: 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))));
		}
	}
开发者ID:nodnarb,项目名称:CCParallaxScrollNode,代码行数:27,代码来源:CCParallaxScrollNode.cpp

示例4: setup

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;
    }

}
开发者ID:1901,项目名称:cocos2d-x,代码行数:32,代码来源:ClippingNodeTest.cpp

示例5: ccTouchesBegan

void ScrollViewDemo::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
{
	CCTouch *touch = (CCTouch*)pTouches->anyObject();
    CCNode *clipper = this->getChildByTag(kTagClipperNode);
	CCPoint point = clipper->convertToNodeSpace(CCDirector::sharedDirector()->convertToGL(touch->getLocationInView()));
    CCRect rect = CCRectMake(0, 0, clipper->getContentSize().width, clipper->getContentSize().height);
    m_bScrolling = rect.containsPoint(point);
    m_lastPoint = point;
}
开发者ID:1901,项目名称:cocos2d-x,代码行数:9,代码来源:ClippingNodeTest.cpp

示例6: 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);
		}
	}
开发者ID:salmanqureshi,项目名称:ecaHack_spacegame,代码行数:15,代码来源:MainMenu.cpp

示例7: relayoutAsVertical

void HRootLayer::relayoutAsVertical(CCArray *nodes, CCPoint basePos, int interval) {
    for (int i = 0; i < nodes->count(); ++i) {
        CCNode *node = (CCNode *)nodes->objectAtIndex(i);
        node->setPosition(CCPointMake(basePos.x, basePos.y + node->getAnchorPoint().y * node->getContentSize().height));
        basePos.y += node->getContentSize().height + interval;
    }
}
开发者ID:hyizsg,项目名称:mytest1st,代码行数:7,代码来源:RootLayer.cpp

示例8: isBeCovered

bool MJHelper::isBeCovered(int layer, cocos2d::CCNode *node)
{
    CCPoint mjPoint = node->getPosition();
    CCSize mjsize = node->getContentSize();
    CCRect mjRect = CCRectMake(mjPoint.x, mjPoint.y, mjsize.width, mjsize.height);//得到要检测麻将的尺寸
    
    mjRect = getZoomRect(0.8, mjRect);
    
    std::string overLayerName;
    overLayerName = overLayerName + ISBeCovered + getstring(layer + 1);//检查将要移除的牌的上面一层
    
    GameState *gs = GameState::getInstance();
    CCArray *layerArr =(CCArray*)gs->getGlobalObject(overLayerName.c_str());
    
    bool covered = false;//没有被覆盖
    
    if (layerArr != NULL) {
        for (int arrNum = 0;arrNum < layerArr->count(); arrNum++)
        {
            CCNode *overNode = (CCNode*)layerArr->objectAtIndex(arrNum);
            CCPoint overPoint = overNode->getPosition();
            CCSize overSize = overNode->getContentSize();
            CCRect overRect = CCRectMake(overPoint.x, overPoint.y, overSize.width, overSize.height);
            
            overRect = getZoomRect(0.8, overRect);
            
            if (mjRect.intersectsRect(overRect)) {
                covered = true;//被覆盖了
            };
        }
    }
    
    return covered;
    
}
开发者ID:GHunique,项目名称:CrazyGeography1,代码行数:35,代码来源:MJHelper.cpp

示例9: ccTouchMoved

void DragLayer::ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent)
{
    //CCLOG("Drag move");
    if (m_isDraging) {
        CCNode *element = getChildByTag(kDragElementTag);
        if (element) {
            CCPoint touchLocation = pTouch->getLocationInView();
            touchLocation = CCDirector::sharedDirector()->convertToGL(touchLocation);
            element->setPosition(touchLocation);
            CCRect rect = CCRectMake(element->getPosition().x - element->getContentSize().width * 0.5f, element->getPosition().y - element->getContentSize().height * 0.5f, element->getContentSize().width, element->getContentSize().height);
            // 先测试一个筐的粘滞效果
            if (rect.containsPoint(m_destinationLayer->getPosition())) {
                CCLOG("开始粘滞");
                CCSprite *spr = CCSprite::create("Icon.png");
                spr->setDisplayFrame(((CCSprite *)element)->displayFrame());
                spr->setPosition(element->getPosition());
                addChild(spr);
                
                //播放粘滞动画
                CCMoveTo *returnToStartPosition = CCMoveTo::create(0.3f, m_destinationLayer->getPosition());
                CCEaseExponentialOut *exponent = CCEaseExponentialOut::create(returnToStartPosition);
                //执行函数
                //CCCallFuncN *call = CCCallFuncN::actionWithTarget(this, callfuncN_selector(DragLayer::removeElement));
                
                CCAction *sequence = CCSequence::create(exponent, NULL);
                spr->runAction(sequence);
                
                removeElement();
            }
        }
    }
}
开发者ID:amengren,项目名称:Sleepy-Bug,代码行数:32,代码来源:DragLayer.cpp

示例10: resetPos

void GiftListView::resetPos()
{
	for (int i=0;i<(int)mPages.count();i++)
		removeChild((CCNode*)mPages.objectAtIndex(i),true);
	mPages.removeAllObjects();
	mPageTotal=0;

	for (int i=0;i<(int)mGiftItems.count();i++)
		((CCNode*)mGiftItems.objectAtIndex(i))->removeFromParentAndCleanup(true);
	
	for (int i=0;i<(int)mGiftItems.count();i++)
	{
		CCNode* item = (CCNode*)mGiftItems.objectAtIndex(i);
		int page = ceil((double)(i+1) / mPageSize);//放到第几页
		int posid = i % mPageSize;//这页第几个

		if (page>mPageTotal) // 如果大于当前页数了,增加一页面
			addPage();

		CCLayer* curpage = (CCLayer*)mPages.objectAtIndex(mPageTotal-1);//最后一页

		int col = posid%mPageRowSize;//第几列
		int row = (int)(posid/mPageRowSize)+1;//第几行
		float itemW = item->getContentSize().width;
		float itemH = item->getContentSize().height;
		float itemX = col*(itemW+mItemIntervalH);
		float itemY = getContentSize().height - (row*(itemH+mItemIntervalV));
		item->setPosition(ccp(itemX,itemY));

		curpage->addChild(item);
	}

}
开发者ID:cjv123,项目名称:PushBoxPlus,代码行数:33,代码来源:GiftListView.cpp

示例11: getRelativeRect

CCRect UIWidget::getRelativeRect()
{
    CCNode* validNode = getValidNode();
    float width = 0.0f;
    float height = 0.0f;
    float anchorPointX = 0.0f;
    float anchorPointY = 0.0f;
    CCSize nodeSize = validNode->getContentSize();
    width = nodeSize.width*getScaleX();
    height = nodeSize.height*getScaleY();
    CCPoint nodeAnchorPoint = validNode->getAnchorPoint();
    anchorPointX = nodeAnchorPoint.x;
    anchorPointY = nodeAnchorPoint.y;
    switch (m_WidgetType)
    {
        case WidgetTypeWidget:
            m_relativeRect.origin.x = getPosition().x - width * anchorPointX;
            m_relativeRect.origin.y = getPosition().y - height * anchorPointY;
            break;
        case WidgetTypeContainer:
            m_relativeRect.origin.x = getPosition().x;
            m_relativeRect.origin.y = getPosition().y;
            break;
    }
    m_relativeRect.size.width = width;
    m_relativeRect.size.height = height;
    return m_relativeRect;
}
开发者ID:chenxu111,项目名称:Cocos2d-x-For-CocoStudio,代码行数:28,代码来源:UIWidget.cpp

示例12:

	CCARRAY_FOREACH(custs,obj)
	{
		CCNode* node =(CCNode*) obj;
		if(bgSpace->convertToWorldSpace(node->getPosition()).x < - node->getContentSize().width)
		{
			bgSpace->incrementOffset(ccp(3000,0),node);
		}
	}
开发者ID:salmanqureshi,项目名称:ecaHack_spacegame,代码行数:8,代码来源:MainMenu.cpp

示例13: tableCellAtIndex

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;
}
开发者ID:longguai,项目名称:game-DarkWar,代码行数:45,代码来源:ListViewLayer.cpp

示例14: init

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

示例15: initBtn

void IOSStoreLayer::initBtn()
{
	//关闭按钮
	CCMenuItemImage* pClose = CCMenuItemImage::create(
		ResManager::getManager()->getSharedFilePath(g_buttonPath+"guanbi.png").c_str(),
		ResManager::getManager()->getSharedFilePath(g_buttonPath+"guanbi_select.png").c_str(), 
		this,
		menu_selector(IOSStoreLayer::menuBtnCallBack));
	pClose->setTag(close_btn_tag);
	m_pBgMenu->addChild(pClose);

	CCNode* pBg = this->getChildByTag(bg_tag);
	if (pBg)
	{
		pClose->setPosition(ccp(pBg->getContentSize().width - pClose->getContentSize().width/2 + 20, 
			pBg->getContentSize().height - pClose->getContentSize().height/2 - 40));
	}
}
开发者ID:SongCF,项目名称:game-LostStar,代码行数:18,代码来源:IOSStoreLayer.cpp


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