Example #1
0
void MenuPopup::OnInit()
{
    node_menu_main_ = Node::create();
    node_menu_main_->setZOrder(getZOrder()+10);
    node_menu_main_->setCascadeOpacityEnabled(true);
    addChild(node_menu_main_);
    
    node_menu_about_ = Node::create();
    node_menu_about_->setZOrder(getZOrder()+10);
    node_menu_about_->setCascadeOpacityEnabled(true);
    addChild(node_menu_about_);
    
    node_menu_help_ = Node::create();
    node_menu_help_->setZOrder(getZOrder()+10);
    node_menu_help_->setCascadeOpacityEnabled(true);
    addChild(node_menu_help_);
    
    node_menu_frame_ = Node::create();
    node_menu_frame_->setZOrder(getZOrder()+5);
    node_menu_frame_->setCascadeOpacityEnabled(true);
    addChild(node_menu_frame_);
    
    
    CreateMainContent();
    CreateAboutContent();
    CreateHelpContent();
        
    sprite_background_ = FSprite::create(DataHandler::TEXTURE_GAME_MAP_1_POPUP);
    sprite_background_->setOpacity(200);
    sprite_background_->setZOrder(getZOrder()+1);
    
#pragma warn message("smaller devices with != WIDESCREEN wil also have 1920x1536 find correct resolution for each device")
    //BACKGROUND
    Vec2 size;
    
    if(DataHandler::app_layout_ != EAppLayout::LAYOUT_WIDESCREEN)
    {
        size = Vec2(1920,1536);
        sprite_background_->setPositionY(150);
    }
    else
    {
        size = Vec2(1920,1080);
    }
    
    sprite_background_->setScale(size.x/sprite_background_->getContentSize().width,size.y/sprite_background_->getContentSize().height);
    addChild(sprite_background_);
    
    scene_->AddTickable(timeframe_active_visible_);
    scene_->AddTickable(state_machine_);
    
    state_machine_.Register(STATE_MAIN, this, &MenuPopup::OnStateMain);
    state_machine_.Register(STATE_ABOUT, this, &MenuPopup::OnStateAbout);
    state_machine_.Register(STATE_HELP, this, &MenuPopup::OnStateHelp);
}
Example #2
0
void ABox::visit(){
	Node::setPosition(ccp(boxBody->GetPosition().x*PTM_RATIO, boxBody->GetPosition().y*PTM_RATIO));

	sprite->setPosition(getPosition());
	sprite->setAnchorPoint(getAnchorPoint());
	sprite->setZOrder(getZOrder());
	sprite->visit();
	if (oldSprite != nullptr)
	{
		oldSprite->setPosition(getPosition());
		oldSprite->setAnchorPoint(getAnchorPoint());
		oldSprite->setZOrder(getZOrder());
		oldSprite->visit();
	}
}
Example #3
0
 // Config the view using Json data
 void ActorView::deserialize(Json::Value &configData)
 {
     View::deserialize(configData);
     
     setRadius   (DataManager::getFloat  (configData, "radius",      getRadius()));
     setZOrder   (DataManager::getInt    (configData, "zOrder",      getZOrder()));
 }
Example #4
0
void Ball::explode(){
	Node* parent = getParent();
	ParticleSystemQuad* explosion_particle = ParticleSystemQuad::create("explosion_particle.plist");
	explosion_particle->setPosition(getPosition());
//	explosion_particle->setEndColor(Color4F(COLOR_CYAN));
	parent->addChild(explosion_particle,getZOrder());
	removeFromParent();
}
	void Slot::setZOrder(float value) {
		if(getZOrder() != value) {
			_offsetZOrder = value - _originZOrder - _tweenZorder;
			if(this->_armature)
			{
				this->_armature->_slotsZOrderChanged = true;
			}
		}
	}
Example #6
0
//override sortAllChildren
void SpriteBatchNode::sortAllChildren()
{
    if (_reorderChildDirty)
    {
        int i = 0,j = 0,length = _children->count();

        // insertion sort
        for(i=1; i<length; i++)
        {
            j = i-1;
            auto tempI = static_cast<Node*>( _children->getObjectAtIndex(i) );
            auto tempJ = static_cast<Node*>( _children->getObjectAtIndex(j) );

            //continue moving element downwards while zOrder is smaller or when zOrder is the same but mutatedIndex is smaller
            while(j>=0 && ( tempI->getZOrder() < tempJ->getZOrder() ||
                           ( tempI->getZOrder() == tempJ->getZOrder() &&
                            tempI->getOrderOfArrival() < tempJ->getOrderOfArrival() ) ) )
            {
                _children->fastSetObject( tempJ, j+1 );
                j = j-1;
                if(j>=0)
                    tempJ = static_cast<Node*>( _children->getObjectAtIndex(j) );
            }
            _children->fastSetObject(tempI, j+1);
        }

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

            int index=0;

            Object* 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(_children, pObj)
            {
                Sprite* child = static_cast<Sprite*>(pObj);
                updateAtlasIndex(child, &index);
            }
        }
Example #7
0
 void Slot::setZOrder(Number value)
 {
     if(getZOrder() != value)
     {
         _offsetZOrder = value - _originZOrder - _tweenZorder;
         if(_armature)
         {
             _armature->_slotsZOrderChanged = true;
         }
     }
 }
Example #8
0
void Hero::initShader() {
    BlockBase::initShader();
    
#if 0
    mTrailFx = ParticleSystemQuad::create("fx/trail.plist");
    mTrailFxNode = ParticleBatchNode::createWithTexture(mTrailFx->getTexture());
    mTrailFxNode->addChild(mTrailFx);
    mTrailFxNode->setPosition(getPosition());
    GameLogic::Game->mParentLayer->addChild(mTrailFxNode, getZOrder() - 2);
#endif
}
Example #9
0
 // Starts playing a given animation (or nothing if this animation is already playing)
 void CocosSpriteActorView::playAnimation(const std::string &name)
 {        
     if (name != _currentAnimation)
     {
         SpriteActorView::playAnimation(name);
     
         if (_currentAnimation != "")
         {
             // Sprite wasn't created yet. Create and set parameters
             if (!_ccSprite)
             {
                 _ccSprite = CCSprite::spriteWithSpriteFrame(((CocosAnimation *)_animations[_currentAnimation].get())->getFirstFrame());    
                 if (_ccSprite)
                 {
                     setPosition(getPosition());
                     setAngle(getAngle());
                     setScale(getScale());
                     setZOrder(getZOrder());
                     setVisible(isVisible());
                     setAlpha(getAlpha());
                 }
             }
             
             // The sprite was created, change texture
             if (_ccSprite)
             {
                 bool isAnimation = _animations[_currentAnimation]->getFrameCount() > 1;
                 
                 CCSpriteFrame *frame = ((CocosAnimation *)_animations[_currentAnimation].get())->getFirstFrame();
                 _ccSprite->setTexture(frame->getTexture());
                 CCRect frameRect = frame->getRectInPixels();
                 if (isAnimation)
                 {
                     frameRect.origin = frame->getOffsetInPixels();
                 }
                 _ccSprite->setTextureRect(frameRect);
                 _ccSprite->setDisplayFrame(frame);
                 
                 // If this animation contains more than one frame, play the animation
                 if (isAnimation)
                 {
                     _ccSprite->runAction(((CocosAnimation *)_animations[_currentAnimation].get())->getAnimationAction());
                 }
             }
             
         }
     }
 }
Example #10
0
void CAFlashView::draw()
{
    CAView::draw();
    ccGLBlendFunc(m_sBlendFunc.src, m_sBlendFunc.dst);
    kmMat4 matrixP;
    kmMat4 matrixMV;
    kmMat4 matrixMVP;
    kmGLGetMatrix(KM_GL_PROJECTION, &matrixP );
    kmGLGetMatrix(KM_GL_MODELVIEW, &matrixMV );
    matrixMV.mat[13] = this->getFrame().size.height + matrixMV.mat[13];
    kmMat4Multiply(&matrixMVP, &matrixP, &matrixMV);
#if CC_ENABLE_GL_STATE_CACHE
    ccGLUseProgram(0);//valid program is NON_ZERO unsigned int
#endif
    CCSize size = this->getFrame().size;
    float localScaleX = size.width/ m_pFlash->getWidth();
    float localScaleY = -(size.height / m_pFlash->getHeight());
    float localScale = localScaleX > -localScaleY ? -localScaleY : localScaleX;
    kmMat4 matrixs;
    kmMat4Scaling(&matrixs, localScale, -localScale, getZOrder());
    kmMat4Multiply(&matrixMVP, &matrixMVP, &matrixs);
    m_pFlash->display(&matrixMVP);
    CHECK_GL_ERROR_DEBUG();
}
Example #11
0
void ClippingNode::visit()
{
    if(!_visible)
        return;
    
    kmGLPushMatrix();
    transform();
    //Add group command
    
    Renderer* renderer = Director::getInstance()->getRenderer();
    
    _groupCommand.init(0,_vertexZ);
    renderer->addCommand(&_groupCommand);

    renderer->pushGroup(_groupCommand.getRenderQueueID());

    _beforeVisitCmd.init(0,_vertexZ);
    _beforeVisitCmd.func = CC_CALLBACK_0(ClippingNode::onBeforeVisit, this);
    renderer->addCommand(&_beforeVisitCmd);
    if (_alphaThreshold < 1)
    {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WINDOWS || CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
#else
        // since glAlphaTest do not exists in OES, use a shader that writes
        // pixel only if greater than an alpha threshold
        GLProgram *program = ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST);
        GLint alphaValueLocation = glGetUniformLocation(program->getProgram(), GLProgram::UNIFORM_NAME_ALPHA_TEST_VALUE);
        // set our alphaThreshold
        program->use();
        program->setUniformLocationWith1f(alphaValueLocation, _alphaThreshold);
        // we need to recursively apply this shader to all the nodes in the stencil node
        // XXX: we should have a way to apply shader to all nodes without having to do this
        setProgram(_stencil, program);
        
#endif

    }
    _stencil->visit();

    _afterDrawStencilCmd.init(0,_vertexZ);
    _afterDrawStencilCmd.func = CC_CALLBACK_0(ClippingNode::onAfterDrawStencil, this);
    renderer->addCommand(&_afterDrawStencilCmd);

    int i = 0;
    
    if(!_children.empty())
    {
        sortAllChildren();
        // draw children zOrder < 0
        for( ; i < _children.size(); i++ )
        {
            auto node = _children.at(i);
            
            if ( node && node->getZOrder() < 0 )
                node->visit();
            else
                break;
        }
        // self draw
        this->draw();
        
        for(auto it=_children.cbegin()+i; it != _children.cend(); ++it)
            (*it)->visit();
    }
    else
    {
        this->draw();
    }

    _afterVisitCmd.init(0,_vertexZ);
    _afterVisitCmd.func = CC_CALLBACK_0(ClippingNode::onAfterVisit, this);
    renderer->addCommand(&_afterVisitCmd);

    renderer->popGroup();
    
    kmGLPopMatrix();
}
Example #12
0
void AlienLayer::moveToAreaFinished(Object* pSender)
{
	setZOrder(getZOrder() + 2);
	currentScaleIdx++;
}
Example #13
0
void NovelLayer::setImage(std::shared_ptr<NovelAction> action)
{
    auto visibleSize = Director::getInstance()->getVisibleSize();
    auto value = action->getValue();
    auto imageName = action->getValue();
    auto target = action->getTarget();
    auto effect = action->getValue2();
    if (target == NovelAction::Target::Left) {
        imageName = StringUtils::format("chat/character/chat_%s.png", imageName.c_str());
        if (_leftChara == NULL) {
            _leftNode = Node::create();
            _leftNode->setPosition(Vec2(0, 0));
            _leftChara = Sprite::create(imageName);
            _leftChara->setAnchorPoint(Vec2(0, 0));
            _leftChara->setPosition(Vec2(20, 50));
            addChild(_leftNode);
            _leftNode->addChild(_leftChara);
        } else {
            if (value == "remove") {
                _leftNameImage->removeFromParent();
                _leftNameImage = NULL;
                _leftChara->removeFromParent();
                _leftChara = NULL;
                _leftBalloon->removeFromParent();
                _leftBalloon = NULL;
                _leftNode->removeFromParent();
                _leftNode = NULL;
            } else {
                _leftChara->setTexture(imageName);
            }
        }
    } else if (target == NovelAction::Target::Right) {
        imageName = StringUtils::format("chat/character/chat_%s.png", imageName.c_str());
        if (_rightChara == NULL) {
            _rightNode = Node::create();
            _rightNode->setPosition(Vec2(visibleSize.width, 0));
            _rightChara = Sprite::create(imageName);
            _rightChara->setAnchorPoint(Vec2(1, 0));
            _rightChara->setPosition(Vec2(-20, 50));
            addChild(_rightNode);
            _rightNode->addChild(_rightChara);
        } else {
            if (value == "remove") {
                _rightNameImage->removeFromParent();
                _rightNameImage = NULL;
                _rightChara->removeFromParent();
                _rightChara = NULL;
                _rightBalloon->removeFromParent();
                _rightBalloon = NULL;
                _rightNode->removeFromParent();
                _rightNode = NULL;
            } else {
                _rightChara->setTexture(imageName);
            }
        }
    } else if (target == NovelAction::Target::Background) {
        if (value == "remove") {
            if (effect == "nextPage") {
                _backGroundImage->runAction(Sequence::create(
                    PageTurn3D::create(0.6f, Size(100, 100)),
                    RemoveSelf::create(),
                    NULL
                ));
            } else if (effect == "fade") {
                _backGroundImage->runAction(Sequence::create(FadeOut::create(1.0f), RemoveSelf::create(), NULL));
            } else {
                _backGroundImage->removeFromParent();
            }
            _backGroundImage = NULL;
        } else {
            if (_backGroundImage == NULL) {
                auto back = Sprite::create(StringUtils::format("chat/back/%s", imageName.c_str()));
                back->setScale(visibleSize.width/back->getContentSize().width);
                back->setAnchorPoint(Vec2(0, 0));
                back->setPosition(Vec2::ZERO);
                back->setZOrder(-1);
                _backGroundImage = NodeGrid::create();
                _backGroundImage->addChild(back);
                _backGroundImage->setCascadeOpacityEnabled(true);
                addChild(_backGroundImage);
                
            } else {
                clearBalloons();
                
                auto removedImage = _backGroundImage;

                auto back = Sprite::create(StringUtils::format("chat/back/%s", imageName.c_str()));
                back->setScale(visibleSize.width/back->getContentSize().width);
                back->setAnchorPoint(Vec2(0, 0));
                back->setPosition(Vec2::ZERO);
                back->setZOrder(removedImage->getZOrder()-1);
                _backGroundImage = NodeGrid::create();
                _backGroundImage->addChild(back);
                _backGroundImage->setCascadeOpacityEnabled(true);
                addChild(_backGroundImage);
                
                if (effect == "nextPage") {
                    removedImage->runAction(Sequence::create(
                        PageTurn3D::create(0.6f, Size(100, 100)),
                        RemoveSelf::create(),
                        NULL
                    ));
                } else {
                    auto dummyBack = LayerColor::create(Color4B::BLACK, visibleSize.width, visibleSize.height);
                    addChild(dummyBack, -100);
                    dummyBack->runAction(Sequence::create(
                        DelayTime::create(1.0f),
                        RemoveSelf::create(),
                        NULL
                    ));

                    removedImage->runAction(Sequence::create(
                        FadeOut::create(1.0f),
                        RemoveSelf::create(),
                        NULL
                    ));
                
                    _backGroundImage->setOpacity(0);
                    _backGroundImage->runAction(FadeIn::create(1.0f));
                }

            }
        }
    }
}
Example #14
0
		virtual bool const operator <(IScreenElement const &other) { return getZOrder() < other.getZOrder(); }
void ProtectedNode::visit(Renderer* renderer, const kmMat4 &parentTransform, bool parentTransformUpdated)
{
    // quick return if not visible. children won't be drawn.
    if (!_visible)
    {
        return;
    }
    
    bool dirty = _transformUpdated || parentTransformUpdated;
    if(dirty)
        _modelViewTransform = this->transform(parentTransform);
    _transformUpdated = false;
    
    
    // IMPORTANT:
    // To ease the migration to v3.0, we still support the kmGL stack,
    // but it is deprecated and your code should not rely on it
    kmGLPushMatrix();
    kmGLLoadMatrix(&_modelViewTransform);
    
    int i = 0;      // used by _children
    int j = 0;      // used by _protectedChildren
    
    sortAllChildren();
    sortAllProtectedChildren();
    
    //
    // draw children and protectedChildren zOrder < 0
    //
    for( ; i < _children.size(); i++ )
    {
        auto node = _children.at(i);
        
        if ( node && node->getZOrder() < 0 )
            node->visit(renderer, _modelViewTransform, dirty);
        else
            break;
    }
    
    for( ; j < _protectedChildren.size(); j++ )
    {
        auto node = _protectedChildren.at(j);
        
        if ( node && node->getZOrder() < 0 )
            node->visit(renderer, _modelViewTransform, dirty);
        else
            break;
    }
    
    //
    // draw self
    //
    this->draw(renderer, _modelViewTransform, dirty);
    
    //
    // draw children and protectedChildren zOrder >= 0
    //
    for(auto it=_protectedChildren.cbegin()+j; it != _protectedChildren.cend(); ++it)
        (*it)->visit(renderer, _modelViewTransform, dirty);
    
    for(auto it=_children.cbegin()+i; it != _children.cend(); ++it)
        (*it)->visit(renderer, _modelViewTransform, dirty);
    
    // reset for next frame
    _orderOfArrival = 0;
    
    kmGLPopMatrix();
}