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))));
            }
        }
    }
Example #2
0
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;
    }
}
// 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))));
		}
	}
Example #4
0
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;
    }

}
Example #5
0
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;
}
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);
		}
	}
Example #7
0
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;
    }
}
Example #8
0
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;
    
}
Example #9
0
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();
            }
        }
    }
}
Example #10
0
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);
	}

}
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;
}
	CCARRAY_FOREACH(custs,obj)
	{
		CCNode* node =(CCNode*) obj;
		if(bgSpace->convertToWorldSpace(node->getPosition()).x < - node->getContentSize().width)
		{
			bgSpace->incrementOffset(ccp(3000,0),node);
		}
	}
Example #13
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;
}
Example #14
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 #15
0
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));
	}
}
Example #16
0
void CCounter::visit()
{
   glEnable(GL_SCISSOR_TEST);
    CCNode* presenter = _presenters->getChildByTag(_digit);
    CCSize size = presenter->getContentSize();
    CCPoint location = this->getParent()->convertToWorldSpace(CCPointMake(this->getPosition().x-size.width*0.5, this->getPosition().y-size.height*0.5));
    glScissor(location.x, location.y, size.width * this->getParent()->getScaleX(), (size.height+2) * this->getParent()->getScaleY());
    CCNode::visit();
    glDisable(GL_SCISSOR_TEST);
}
Example #17
0
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);;
}
Example #18
0
void SFFiniteLayer::setPosition(const CCPoint & tPosition)
{
	CCPoint position = tPosition;
	CCNode * parent = this->getParent();
	if (parent)
	{
		CCSize winSize = parent->getContentSize();
		CCRect rect = CCRect(0, 0, winSize.width, winSize.height);
		position = CNFiniteLayer::limitPosition(this, position, rect);
	}
	CNLayer::setPosition(position);
}
Example #19
0
bool AllianceTitleRankCell::init()
{
    bool ret = true;
    
    if (CCNode::init()) {
        CCNode* node = CCBLoadFile("AllianceTitleRankCell", this, this);
        CCSize size = node->getContentSize();
        setContentSize(size);
        return true;
    }
    return ret;
}
Example #20
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 #21
0
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);
}
Example #22
0
	void CCMenu::alignItemsVerticallyWithPadding(float padding)
	{
		float height = -padding;
		if (m_pChildren && m_pChildren->count() > 0)
		{
            CCObject* pObject = NULL;
            CCARRAY_FOREACH(m_pChildren, pObject)
            {
                CCNode* pChild = (CCNode*) pObject;
                if (pChild)
                {
                    height += pChild->getContentSize().height * pChild->getScaleY() + padding;
                }
            }
Example #23
0
CCPoint HelloWorld::mainmenupos(int pos)
{
    CCSize WinSize = CCDirector::sharedDirector()->getWinSize();
    CCNode *pNode = (CCNode *)getChildByTag(TAG_MAINMENU);
    CCSize nodesize = pNode->getContentSize();
    if (pos == POS_IN)
    {
        return ccp(WinSize.width/2, WinSize.height/2-100);
    }
    else
    {
        return ccp(WinSize.width+nodesize.width/2, WinSize.height/2-100);
    }
}
void VEScrollView::reArrange()
{
    CCArray *children = m_pContainer->getChildren();

    float posX = -m_viewSize.width/2.f;
    float posY = m_viewSize.height/2.f;

    for(int i = 0; i < m_pContainer->getChildrenCount(); i++)
    {
        CCNode *node = (CCNode*)children->objectAtIndex(i);
        CCSize nodeSize = node->getContentSize();
        node->setAnchorPoint(ccp(0.5, 0.5));
        switch (m_eType) {
        case SCROLLVIEW_HORIZONTAL:
            node->setPositionX(posX+nodeSize.width/2.f);
            posX += nodeSize.width;
            break;
        case SCROLLVIEW_VERTICAL:
            node->setPositionY(posY-nodeSize.height/2.f);
            posY -= nodeSize.height;
            break;
        default:
            CCLOG("wrong scroll type");
            break;
        }
        //float nodeY = m_pContainer->getPositionY()+h;
        //node->setVisible(nodeY<nodeSize.height && nodeY>-m_viewSize.height);
        //if(dynamic_cast<CCLayer*>(node))
        //   dynamic_cast<CCLayer*>(node)->setTouchEnabled(nodeY<nodeSize.height && nodeY>-m_viewSize.height);

    }


    switch (m_eType) {
    case SCROLLVIEW_HORIZONTAL:
        posX += m_viewSize.width/2.f;
        m_contentSize.width = abs(posX);
        m_contentSize.height = m_viewSize.height;
        break;
    case SCROLLVIEW_VERTICAL:
        posY -= m_viewSize.height/2.f;
        m_contentSize.width = m_viewSize.width;
        m_contentSize.height = abs(posY);
        break;
    default:
        CCLOG("wrong scroll type");
        break;
    }
}
Example #25
0
CCPoint HelloWorld::toolbarpos(int pos)
{
    CCSize WinSize = CCDirector::sharedDirector()->getWinSize();
    CCNode *pNode = (CCNode *)getChildByTag(TAG_TOOLBAR);
    CCSize nodesize = pNode->getContentSize();
    if (pos == POS_IN)
    {
        return ccp(0, WinSize.height-nodesize.height);
        
    }
    else
    {
        return ccp(0, WinSize.height);
    }
}
Example #26
0
CCPoint HelloWorld::aboutpos(int pos)
{
    CCSize WinSize = CCDirector::sharedDirector()->getWinSize();
    CCNode *pNode = (CCNode *)getChildByTag(TAG_ABOUT);
    CCSize nodesize = pNode->getContentSize();
    if (pos == POS_IN)
    {
        return ccp((WinSize.width-nodesize.width)/2,
                   (WinSize.height-nodesize.height)/2);
        
    }
    else
    {
        return ccp(WinSize.width, (WinSize.height-nodesize.height)/2);
    }
}
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 #28
0
CCPoint HelloWorld::titlepos(int pos)
{
    CCSize WinSize = CCDirector::sharedDirector()->getWinSize();
    CCNode *pNode = (CCNode *)getChildByTag(TAG_TITLE);
    CCSize nodesize = pNode->getContentSize();
    
    if (pos == POS_IN)
    {
        return ccp(WinSize.width/2, WinSize.height/2+nodesize.height);
    
    }
    else
    {
        return ccp(-nodesize.width/2, WinSize.height/2+nodesize.height);
    
    }
}
void GameScene::setBall() {
	//ボールをバー上に配置する
	if (m_balls->count() <= 0) {
		return;
	}
	BallSprite* ball = dynamic_cast<BallSprite*>(m_balls->objectAtIndex(0));
	CCNode *bar = this->getChildByTag(kTagBar);
//	CCRect rect = bar->boundingBox();
	ball->setPosition(
			ccp(bar->getPositionX(), bar->getPositionY() + bar->getContentSize().height + 10));
//    CCLOG("# setBall #bar.width: %f, height: %f",
//          bar->getContentSize().width, bar->getContentSize().height);
//    CCLOG("# setBall #bar position X: %f, Y: %f",
//          bar->getPositionX(), bar->getPositionY());
//	ball->setPosition(
//			ccp(bar->getPositionX() + bar->getContentSize().width / 2, bar->getPositionY() + bar->getContentSize().height));
	this->addChild(ball);

	m_balls->removeObjectAtIndex(0);
	m_activeballs->addObject(ball);
}
Example #30
0
void E002_C010_P230::_setPositionOutParent(CCNode* child, CCNode* newParent)
{
    CCNode* parent = (CCNode*)child->getParent();
    if (parent && child) {
    
        child->retain();
        
        CCSize parentSize = parent->getContentSize();
        CCPoint parentAnchor = parent->getAnchorPoint();
        
        float posX =  parent->getPositionX() - parentSize.width*parentAnchor.x + child->getPositionX();
        float posY =  parent->getPositionY() - parentSize.height*parentAnchor.y + child->getPositionY();
    
        child->removeFromParentAndCleanup(false);
        child->setPosition(ccp(posX, posY));
        this->addChild(child);
        
        child->release();
    }
    
}