Example #1
0
void Widget::sortAllChildren()
{
    _reorderWidgetChildDirty = m_bReorderChildDirty;
    CCNode::sortAllChildren();
    if( _reorderWidgetChildDirty )
    {
        int i,j,length = _widgetChildren->data->num;
        CCNode ** x = (CCNode**)_widgetChildren->data->arr;
        CCNode *tempItem;
        
        // insertion sort
        for(i=1; i<length; i++)
        {
            tempItem = x[i];
            j = i-1;
            
            //continue moving element downwards while zOrder is smaller or when zOrder is the same but mutatedIndex is smaller
            while(j>=0 && ( tempItem->getZOrder() < x[j]->getZOrder() || ( tempItem->getZOrder()== x[j]->getZOrder() && tempItem->getOrderOfArrival() < x[j]->getOrderOfArrival() ) ) )
            {
                x[j+1] = x[j];
                j = j-1;
            }
            x[j+1] = tempItem;
        }
        
        //don't need to check children recursively, that's done in visit of each child
        
        _reorderWidgetChildDirty = false;
    }
}
Example #2
0
void LCWordCloudLayer::ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent)
{
	if (!m_bIsMoved) {
		// tap action : select something
		CCNode *selectedNode = NULL;
		for (int i=0; i<m_pNodeArray->count(); i++) {
			CCNode *pNode = (CCNode *)m_pNodeArray->objectAtIndex(i);
			if (LCUtil::isTouchInside(pNode, pTouches)) {
				if (selectedNode) {
					if (selectedNode->getZOrder() < pNode->getZOrder()) {
						selectedNode = pNode;
					}
				} else {
					selectedNode = pNode;
				}
				
			}
		}
		
		if (selectedNode) {
			if (m_pLCWordCloudLayerDelegate) {
				m_pLCWordCloudLayerDelegate->wordCloudDidSelectedWord(this, selectedNode);
			} else {
				CCLog("You can control selected node event with WordCloudLayerDelegate::didWordSelected");
			}
		}
	}
}
Example #3
0
void CSmeltArmor::initFire()
{
	//获取参考位置
	CCNode* pNode = (CCNode*)m_ui->findWidgetById("fire_circle");
	CCPoint pPos = ccp(pNode->getPositionX()+15, pNode->getPositionY()+75);

	if(m_pFire1 == nullptr)
	{
		CCAnimation* pAnimation = AnimationManager::sharedAction()->getAnimation("9010");
		pAnimation->setDelayPerUnit(0.15f);
		m_pFire1 = CCSprite::create("skill/9010.png");
		m_pFire1->setPosition(pPos);
		m_pFire1->runAction(CCRepeatForever::create(CCAnimate::create(pAnimation)));
		m_pFire1->setVisible(false);
		m_pFire1->setScale(1.6f);
		pNode->getParent()->addChild(m_pFire1, pNode->getZOrder());
	}
	if(m_pFire2 == nullptr)
	{
		CCAnimation* pAnimation = AnimationManager::sharedAction()->getAnimation("9011");
		pAnimation->setDelayPerUnit(0.15f);
		m_pFire2 = CCSprite::create("skill/9011.png");
		m_pFire2->setPosition(pPos);
		m_pFire2->runAction(CCRepeatForever::create(CCAnimate::create(pAnimation)));
		m_pFire2->setVisible(false);
		m_pFire2->setScale(1.5f);
		pNode->getParent()->addChild(m_pFire2, pNode->getZOrder());
	}
}
Example #4
0
// helper used by reorderChild & add
void CCNode::insertChild(CCNode* child, int z)
{
    unsigned int index = 0;
    CCNode* a = m_pChildren->getLastObject();
    if (!a || a->getZOrder() <= z)
    {
        m_pChildren->addObject(child);
    }
    else
    {
        CCNode* pNode;
        CCMutableArray<CCNode*>::CCMutableArrayIterator it;
        for( it = m_pChildren->begin(); it != m_pChildren->end(); it++)
        {
            pNode = (*it);

            if ( pNode && pNode->m_nZOrder > z ) 
            {
                m_pChildren->insertObjectAtIndex(child, index);
                break;
            }
            index++;
        }
    }

    child->setZOrder(z);
}
//override sortAllChildren
void CCSpriteBatchNode::sortAllChildren()
{
    if (m_bReorderChildDirty)
    {
        int i = 0,j = 0,length = m_pChildren->data->num;
        CCNode ** x = (CCNode**)m_pChildren->data->arr;
        CCNode *tempItem = NULL;

        //insertion sort
        for(i=1; i<length; i++)
        {
            tempItem = x[i];
            j = i-1;

            //continue moving element downwards while zOrder is smaller or when zOrder is the same but orderOfArrival is smaller
            while(j>=0 && ( tempItem->getZOrder() < x[j]->getZOrder() || ( tempItem->getZOrder() == x[j]->getZOrder() && tempItem->getOrderOfArrival() < x[j]->getOrderOfArrival() ) ) )
            {
                x[j+1] = x[j];
                j--;
            }

            x[j+1] = tempItem;
        }

        //sorted now check all children
        if (m_pChildren->count() > 0)
        {
            //first sort all children recursively based on zOrder
            arrayMakeObjectsPerformSelector(m_pChildren, sortAllChildren, CCSprite*);

            int index=0;

            CCObject* pObj = NULL;
            //fast dispatch, give every child a new atlasIndex based on their relative zOrder (keep parent -> child relations intact)
            // and at the same time reorder descendants and the quads to the right index
            CCARRAY_FOREACH(m_pChildren, pObj)
            {
                CCSprite* pChild = (CCSprite*)pObj;
                updateAtlasIndex(pChild, &index);
            }
        }
void CC3DSprite::visit( void )
{
	m_drawOrder = ++g_drawOrder;
	// quick return if not visible. children won't be drawn.
	if (!m_bVisible) return;
	kmGLPushMatrix();

	this->transform();

	CCNode* pNode = NULL;
	unsigned int i = 0;

	if(m_pChildren && m_pChildren->count() > 0)
	{
		sortAllChildren();
		// draw children zOrder < 0
		ccArray *arrayData = m_pChildren->data;
		for( ; i < arrayData->num; i++ )
		{
			pNode = (CCNode*) arrayData->arr[i];

			if ( pNode && pNode->getZOrder() < 0 )
			{
				pNode->visit();
			}
			else
			{
				break;
			}
		}
		// self draw
		this->draw();

		for( ; i < arrayData->num; i++ )
		{
			pNode = (CCNode*) arrayData->arr[i];
			if (pNode)
			{
				pNode->visit();
			}
		}
	}
	else
	{
		this->draw();
	}

	// reset for next frame
	m_uOrderOfArrival = 0;

	kmGLPopMatrix();
}
unsigned int CCParticleBatchNode::searchNewPositionInChildrenForZ(int z)
{
    unsigned int count = m_pChildren->count();

    for( unsigned int i=0; i < count; i++ ) 
    {
        CCNode *child = (CCNode *)m_pChildren->objectAtIndex(i);
        if (child->getZOrder() > z)
        {
            return i;
        }
    }
    return count;
}
void CCParticleBatchNode::getCurrentIndex(unsigned int* oldIndex, unsigned int* newIndex, CCNode* child, int z)
{
    bool foundCurrentIdx = false;
    bool foundNewIdx = false;

    int  minusOne = 0;
    unsigned int count = m_pChildren->count();

    for( unsigned int i=0; i < count; i++ ) 
    {
        CCNode* pNode = (CCNode *)m_pChildren->objectAtIndex(i);

        // new index
        if( pNode->getZOrder() > z &&  ! foundNewIdx ) 
        {
            *newIndex = i;
            foundNewIdx = true;

            if( foundCurrentIdx && foundNewIdx )
            {
                break;
            }
        }

        // current index
        if( child == pNode ) 
        {
            *oldIndex = i;
            foundCurrentIdx = true;

            if( ! foundNewIdx )
            {
                minusOne = -1;
            }

            if( foundCurrentIdx && foundNewIdx )
            {
                break;
            }
        }

    }

    if( ! foundNewIdx )
    {
        *newIndex = count;
    }

    *newIndex += minusOne;
}
Example #9
0
void GridEffectSprite::visit()
{
	// quick return if not visible. children won't be drawn.
	if (!m_bVisible)
	{
		return;
	}
	kmGLPushMatrix();

	if (m_pGrid && m_pGrid->isActive())
	{
		m_pGrid->beforeDraw();
	}

	this->transform();

	CCNode* pNode = NULL;
	unsigned int i = 0;

	if(m_pChildren && m_pChildren->count() > 0)
	{
		sortAllChildren();
		// draw children zOrder < 0
		ccArray *arrayData = m_pChildren->data;
		for( ; i < arrayData->num; i++ )
		{
			pNode = (CCNode*) arrayData->arr[i];
			if (pNode == m_originalSprite) continue;
			if ( pNode && pNode->getZOrder() < 0 ) 
			{
				pNode->visit();
			}
			else
			{
				break;
			}
		}
		// self draw
		this->draw();

		for( ; i < arrayData->num; i++ )
		{
			pNode = (CCNode*) arrayData->arr[i];
			if (pNode == m_originalSprite) continue;
			if (pNode)
			{
				pNode->visit();
			}
		}        
	}
	else
	{
		this->draw();
	}

	// reset for next frame
	m_uOrderOfArrival = 0;

	if (m_pGrid && m_pGrid->isActive())
	{
		m_pGrid->afterDraw(this);
	}

	kmGLPopMatrix();
}
Example #10
0
void UILayoutRenderNode::visit()
{
	cocos2d::CCSize size = CCDirector::sharedDirector()->getWinSize();
	cocos2d::CCPoint cameraOffset = CCDirector::sharedDirector()->getLevelRenderCameraOffset();
	float zeye = CCDirector::sharedDirector()->getZEye();
	
	// quick return if not visible
	if (!m_bVisible)
	{
		return;
	}
	kmGLPushMatrix();

	//TODO: don't need change camera everytime
	//it costs much time
	kmGLMatrixMode(KM_GL_MODELVIEW);
	kmGLLoadIdentity();
/*
	gluLookAt( size.width/2 + cameraOffset.x, size.height/2 + cameraOffset.y, zeye,
		size.width/2 + cameraOffset.x, size.height/2 + cameraOffset.y, 0,
		0.0f, 1.0f, 0.0f);*/

	kmVec3 eye, center, up;
	kmVec3Fill( &eye,  size.width/2 + cameraOffset.x, size.height/2 + cameraOffset.y, zeye);
	kmVec3Fill( &center, size.width/2 + cameraOffset.x, size.height/2 + cameraOffset.y, 0 );
	kmVec3Fill( &up, 0.0f, 1.0f, 0.0f);

	kmMat4 matrixLookup;
	kmMat4LookAt(&matrixLookup, &eye, &center, &up);
	kmGLMultMatrix(&matrixLookup);


 	if (m_pGrid && m_pGrid->isActive())
 	{
 		m_pGrid->beforeDraw();
 		this->transformAncestors();
 	}

	this->transform();

    CCNode* pNode = NULL;
    unsigned int i = 0;

	if(m_pChildren && m_pChildren->count() > 0)
	{
		// draw children zOrder < 0
        ccArray *arrayData = m_pChildren->data;
        for( ; i < arrayData->num; i++ )
        {
            pNode = (CCNode*) arrayData->arr[i];

			if ( pNode && pNode->getZOrder() < 0 ) 
			{
				pNode->visit();
			}
			else
			{
				break;
			}
		}
    }

	// self draw
	this->draw();

	// draw children zOrder >= 0
    if (m_pChildren && m_pChildren->count() > 0)
    {
        ccArray *arrayData = m_pChildren->data;
        for( ; i < arrayData->num; i++ )
        {
            pNode = (CCNode*) arrayData->arr[i];
            if (pNode)
            {
                pNode->visit();
            }
		}		
	}

 	if (m_pGrid && m_pGrid->isActive())
 	{
 		m_pGrid->afterDraw(this);
	}
 
	kmGLPopMatrix();
}
void SpaceBackGround::InitBG(cocos2d::CCNode *layer)
{
    glClearColor(0.0f/255.0f, 0.0f/255.0f, 0.0f/255.0f, 1.0f);
    m_layer = layer;
    pNode = CCParallaxNodeTile::create();
    m_layer->addChild(pNode);
    
        
    CCSize s = CCDirector::sharedDirector()->getWinSize();
    //////////////
    //Adding some comments to test out a git pull request
    //
    //
    bool nasaObjsLoaded = true;
    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("spaceBG.plist","spaceBG.png");
    
    float scale = ScreenHelper::getTextureScale();
    float scaleX = ScreenHelper::getTextureScaleX();
    float scaleY = ScreenHelper::getTextureScaleY();
    
    CCSprite *sprite = CCSprite::create("ctm_SpaceGradient_Merged_BG.png");
    sprite->setScaleX(s.width/940.0f);
    sprite->setScaleY(s.width/940.0f);
    pNode->addChild(sprite,0,CCPointMake(1.0f,0.0f),ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_CENTER,0.0f,40.0f));
    
    CCSprite *moon;
    switch (RandomInt(0, 7)) {
        default:
        case 0:
            moon = CCSprite::create("ctm_Nasa_Jupitor.png");
            break;
        case 1:
            moon = CCSprite::create("ctm_Nasa_Mars.png");
            break;
        case 2:
            moon = CCSprite::create("ctm_Nasa_Mercury.png");
            break;
        case 3:
            moon = CCSprite::create("ctm_Nasa_Neptune.png");
            break;
        case 4:
            moon = CCSprite::create("ctm_Nasa_Saturn.png");
            break;
        case 5:
            moon = CCSprite::create("ctm_Nasa_Uranus.png");
            break;
        case 6:
            moon = CCSprite::create("ctm_Nasa_Venus.png");
            break;
    }
    moon->setAnchorPoint(ccp(0.5f,0.5f));
    moon->setScale(scale);
    pNode->addChild(moon,0,CCPointMake(1.0f,0.0f),ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_CENTER,RandomFloat(-200.0f, 100.0f),RandomFloat(-25.0f, 25.0f)));
    
    m_Parallax1 = CCArray::createWithCapacity(4);
    m_Parallax1->retain();
    for(int i = 0; i < 4; i++)
    {
        char temp[64];
        sprintf(temp,"ctm_Moon_%02d.png",i+1);
        sprite = CCSprite::create(temp);
        sprite->setScale(scale);
        m_Parallax1Points[i] = ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_BOTTOM_LEFT, 256.0f*i, 53.0f);
        pNode->addChild(sprite,1,CCPointMake(0.90f,0.0f),m_Parallax1Points[i]);
        m_Parallax1->addObject(sprite);
        
    }
    
    if(nasaObjsLoaded)
    {
        m_Parallax2 = CCArray::createWithCapacity(4);
        m_Parallax2->retain();
        m_Parallax3 = CCArray::createWithCapacity(4);
        m_Parallax3->retain();
        
        int last = -1;
        std::vector<int> poster_rand;
        std::vector<int> retro_rand;
        object_vals.clear();
        for(int i = 0; i < 4; i++)
        {

            //head
            char name[64];
            if(last != 0 && RandomInt(0, 100)>90)
            {
                if(poster_rand.size()>0){
                    int new_rand;
                    bool found = false;
                    do{
                        found = false;
                        new_rand = RandomInt(1, 7);
                        for(int j=0; j < poster_rand.size(); j++){
                            int val = poster_rand[j];
                            if(val == new_rand){
                                found = true;
                                break;
                            }
                        }
                    }while(found);
                    poster_rand.push_back(new_rand);
                }else{
                    poster_rand.push_back(RandomInt(1, 7));
                }
                last = 0;
                sprintf(name,"ctm_SpacePoster_%02d.png",poster_rand.back());
                sprite = CCSprite::createWithSpriteFrameName(name);
                sprite->setScale(scale);
                m_Parallax2Points[i] = ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_BOTTOM_LEFT, 256.0f*i-192.0f, 103.0f);
                pNode->addChild(sprite,2,CCPointMake(0.90f,0.0f),m_Parallax2Points[i]);
                m_Parallax2->addObject(sprite);
            }
            else
            {
                last = 1;
                if(retro_rand.size()>0){
                    int new_rand;
                    bool found = false;
                    do{
                        found = false;
                        new_rand = RandomInt(1, 6);
                        for(int j=0; j < retro_rand.size(); j++){
                            int val = retro_rand[j];
                            if(val == new_rand){
                                found = true;
                                break;
                            }
                        }
                    }while(found);
                    retro_rand.push_back(new_rand);
                }else{
                    retro_rand.push_back(RandomInt(1, 6));
                }
                sprintf(name,"ctm_space_Retro%02d.png",(RandomInt(1, 6)));
                CCNode *object = getBGObject();
                m_Parallax2Points[i] = ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_BOTTOM_LEFT, 256.0f*i-128.0f+object->getPositionX(), 103.0f+object->getPositionY());
                pNode->addChild(object,object->getZOrder(),CCPointMake(0.90f,0.0f),m_Parallax2Points[i]);
                m_Parallax2->addObject(object);
            }
            
            //torch
            CCNode *object = getBGObject();
            m_Parallax3Points[i] = ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_BOTTOM_LEFT, 256.0f*i+object->getPositionX(), 103.0f+object->getPositionY());
            pNode->addChild(object,object->getZOrder(),CCPointMake(0.90f,0.0f),m_Parallax3Points[i]);
            m_Parallax3->addObject(object);
        }
        
    }
    else
    {
        m_Parallax2 = NULL;
    }
    
    
    
    m_Track = CCArray::createWithCapacity(4);
    m_Track->retain();
    for(int i = 0; i < 4; i++)
    {
        int r = 2.999f * CCRANDOM_0_1();
        switch(r){
            default:
            case 0:
                sprite = CCSprite::create("Space_Panels_01.png");
                break;
            case 1:
                sprite = CCSprite::create("Space_Panels_02.png");
                break;
            case 2:
                sprite = CCSprite::create("Space_Panels_03.png");
                break;
        }
        sprite->setScaleX(scaleX);
        sprite->setScaleY(scaleY);
        m_TrackPoints[i] = ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_BOTTOM_LEFT);
        m_TrackPoints[i].x += (256.0f*i)*scaleX;
        m_TrackPoints[i].y += -28.0f*scale;
        sprite->setPosition(m_TrackPoints[i]);
        m_layer->addChild(sprite,4);
        m_Track->addObject(sprite);
        
        /*       sprite = CCSprite::create("ctm_256_Front_hazardstripe.png");
         sprite->setScaleX(scaleX);
         sprite->setScaleY(scaleY);
         sprite->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_BOTTOM_LEFT, 256.0f*i, 55.0f));
         addChild(sprite,4);
         */
    }
    
    
}