// override addChild:
void ParticleBatchNode::addChild(Node * aChild, int zOrder, int tag)
{
    CCASSERT( aChild != nullptr, "Argument must be non-nullptr");
    CCASSERT( dynamic_cast<ParticleSystem*>(aChild) != nullptr, "CCParticleBatchNode only supports QuadParticleSystems as children");
    ParticleSystem* child = static_cast<ParticleSystem*>(aChild);
    CCASSERT( child->getTexture()->getName() == _textureAtlas->getTexture()->getName(), "CCParticleSystem is not using the same texture id");
    // If this is the 1st children, then copy blending function
    if (_children.empty())
    {
        setBlendFunc(child->getBlendFunc());
    }

    CCASSERT( _blendFunc.src  == child->getBlendFunc().src && _blendFunc.dst  == child->getBlendFunc().dst, "Can't add a ParticleSystem that uses a different blending function");

    //no lazy sorting, so don't call super addChild, call helper instead
    auto pos = addChildHelper(child,zOrder,tag);

    //get new atlasIndex
    int atlasIndex = 0;

    if (pos != 0)
    {
        ParticleSystem* p = static_cast<ParticleSystem*>(_children.at(pos-1));
        atlasIndex = p->getAtlasIndex() + p->getTotalParticles();
    }
    else
    {
        atlasIndex = 0;
    }

    insertChild(child, atlasIndex);

    // update quad info
    child->setBatchNode(this);
}
示例#2
0
文件: FocusLayer.cpp 项目: dnrl/ur
void FocusLayer::addCircle(const Vec2& pos, float radius, onTouchCallback callback)
{
    auto node = DrawNode::create();
    node->setPosition(pos);
    node->drawDot(Vec2::ZERO, radius, Color4F(1, 1, 1, 1));
    node->setTag(_circleIdx);
    addChild(node);
    node->retain();
    
    BlendFunc blend;
    blend.src = GL_DST_COLOR;
    blend.dst = GL_ONE;
    node->setBlendFunc(blend);
    
    circleData data;
    data._pos = pos;
    data._radius = radius;
    data._callback = callback;
    data._node = node;
    
    _circleList.insert(std::make_pair(_circleIdx++, data));
    
    node->setScale(0);
    node->runAction(EaseBackOut::create(ScaleTo::create(0.4f, 1.0f)));
}
示例#3
0
文件: FocusLayer.cpp 项目: dnrl/ur
void FocusLayer::addRect(const Vec2& pos, const Size& size, onTouchCallback callback)
{
    Vec2 rc[4];
    rc[0] = Vec2(-size.width/2, -size.height/2);
    rc[1] = Vec2(size.width/2, -size.height/2);
    rc[2] = Vec2(size.width/2, size.height/2);
    rc[3] = Vec2(-size.width/2, size.height/2);
    
    auto rcNode = DrawNode::create();
    rcNode->setPosition(pos);
    rcNode->drawPolygon(rc, 4, Color4F(1, 1, 1, 1), 0, Color4F(1, 1, 1, 1));
    rcNode->setTag(_rectIdx);
    addChild(rcNode);
    
    BlendFunc blend;
    blend.src = GL_DST_COLOR;
    blend.dst = GL_ONE;
    rcNode->setBlendFunc(blend);
    
    rectData data;
    data._pos = pos;
    data._rect = Rect(pos.x - size.width/2, pos.y - size.height/2, size.width, size.height);
    data._callback = callback;
    data._node = rcNode;
    
    _rectList.insert(std::make_pair(_rectIdx++, data));
    
    rcNode->setScale(0);
    rcNode->runAction(EaseBackOut::create(ScaleTo::create(0.4f, 1.0f)));
}
void ParticleBatchNode::addChildByTagOrName(ParticleSystem* child, int zOrder, int tag, const std::string &name, bool setTag)
{
    // If this is the 1st children, then copy blending function
    if (_children.empty())
    {
        setBlendFunc(child->getBlendFunc());
    }
    
    CCASSERT( _blendFunc.src  == child->getBlendFunc().src && _blendFunc.dst  == child->getBlendFunc().dst, "Can't add a ParticleSystem that uses a different blending function");
    
    //no lazy sorting, so don't call super addChild, call helper instead
    int pos = 0;
    if (setTag)
        pos = addChildHelper(child, zOrder, tag, "", true);
    else
        pos = addChildHelper(child, zOrder, 0, name, false);
    
    //get new atlasIndex
    int atlasIndex = 0;
    
    if (pos != 0)
    {
        ParticleSystem* p = static_cast<ParticleSystem*>(_children.at(pos-1));
        atlasIndex = p->getAtlasIndex() + p->getTotalParticles();
    }
    else
    {
        atlasIndex = 0;
    }
    
    insertChild(child, atlasIndex);
    
    // update quad info
    child->setBatchNode(this);
}
示例#5
0
void BoneNode::addToSkinList(SkinNode* skin)
{
    _boneSkins.pushBack(skin);
    auto blendSkin = dynamic_cast<BlendProtocol*>(skin);
    if (nullptr != blendSkin && _blendFunc != blendSkin->getBlendFunc())
    {
        blendSkin->setBlendFunc(_blendFunc);
    }
}
示例#6
0
void BlendFuncFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
{
    if(_node)
    {
        auto blendnode = dynamic_cast<BlendProtocol*>(_node);
        if(blendnode)
            blendnode->setBlendFunc(_blendFunc);
    }
}
	void PVRESettings::Init()
	{
		// default blending value
		setBlendFunc(ePODBlendFunc_SRC_ALPHA,ePODBlendFunc_ONE_MINUS_SRC_ALPHA);

		// everything is dirty to start with so everything must be set
		// and no default state is assumed.
		// So responsibility is to the app for initialisation

		m_u32DirtyFlags=0xffffffff;
	}
示例#8
0
bool ResultScene::init(){
    if (!Layer::init()){
        return false;
    }

    auto visibleSize = Director::getInstance()->getVisibleSize();

    auto bgimage = Sprite::create("background/dimension-light.png");
    this->addChild(bgimage, Z_BACK);
    bgimage->setPosition(visibleSize / 2);
    bgimage->setScale(1.3);

    auto bgimage2 = Sprite::create("background/water.png");
    this->addChild(bgimage2, Z_BACK);
    bgimage2->setPosition(0, visibleSize.height / 2);
    bgimage2->setAnchorPoint(Vec2(0, 0.5));
    bgimage2->setScale(3, 1.3);
    bgimage2->setBlendFunc(GL_BLEND_SCREENMODE);
    bgimage2->setOpacity(200);
    bgimage2->setTag(100);

    auto tempText = LabelTTF::create("Total money you get: ", "Segoe UI", 36);
    tempText->setPosition(100, visibleSize.height - 300);
    tempText->setHorizontalAlignment(TextHAlignment::LEFT);
    tempText->setVerticalAlignment(TextVAlignment::CENTER);
    tempText->setAnchorPoint(Vec2(0, 0.5));
    tempText->setTag(101);
    this->addChild(tempText, Z_UI);

    auto amountPla = LabelTTF::create("Amount of planaria you make: ", "Segoe UI", 36);
    amountPla->setPosition(tempText->getPositionX(), tempText->getPositionY() - 60);
    amountPla->setHorizontalAlignment(TextHAlignment::LEFT);
    amountPla->setVerticalAlignment(TextVAlignment::CENTER);
    amountPla->setAnchorPoint(Vec2(0, 0.5));
    amountPla->setTag(102);
    this->addChild(amountPla, Z_UI);

    auto amountDead = LabelTTF::create("Amount of planaria you cut: ", "Segoe UI", 36);
    amountDead->setPosition(amountPla->getPositionX(), amountPla->getPositionY() - 60);
    amountDead->setHorizontalAlignment(TextHAlignment::LEFT);
    amountDead->setVerticalAlignment(TextVAlignment::CENTER);
    amountDead->setAnchorPoint(Vec2(0, 0.5));
    amountDead->setTag(103);
    this->addChild(amountDead, Z_UI);

    this->schedule(schedule_selector(ResultScene::Mainloop));

    b2Aquarium = Sprite::create("retry.png"); \
    b2Aquarium->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM); \
    b2Aquarium->setPosition(visibleSize.width / 2, 0); \
    this->addChild(b2Aquarium);

    return true;
}
示例#9
0
void SE_BlendState::apply()
{
	if(mBlendProperty == BLEND_ENABLE)
	{
		glEnable(GL_BLEND);
		setBlendFunc();
	}
	else
	{
		glDisable(GL_BLEND);
	}
}
示例#10
0
void BoneNode::setBlendFunc(const cocos2d::BlendFunc& blendFunc)
{
    if (_blendFunc != blendFunc)
    {
        _blendFunc = blendFunc;
        for (auto & skin : _boneSkins)
        {
            auto blendSkin = dynamic_cast<BlendProtocol*>(skin);
            if (nullptr != blendSkin)
            {
                blendSkin->setBlendFunc(_blendFunc);
            }
        }
    }
}
示例#11
0
void GraphicEngine::initGL() {
	
	// Light init
	if (game->config->getInt("lighting"))
		glEnable(GL_LIGHTING);

	glEnable(GL_COLOR_MATERIAL);
	glEnable(GL_TEXTURE_2D);

	setAmbient(MGColor(0.5f, 0.5f, 0.5f, 1.0f));
	setClearColor(MGColor(0.0f, 0.0f, 0.0f, 1.0f));

	//glPolygonMode(GL_FRONT, GL_LINE);
	//glPolygonMode(GL_BACK, GL_LINE);	
	
	glShadeModel (GL_SMOOTH); // ћетод закраски: —√Ћј∆≈Ќџ… 
	glEnable (GL_DEPTH_TEST); // ¬ключаем тест глубины 
	// ¬ Ћ. ј¬“ќћј“»„≈— »… ѕ≈–≈—„≈“ Ќќ–ћјЋ≈… 
	//glEnable (GL_AUTO_NORMAL); 
	glEnable (GL_NORMALIZE); 
	// ¬ Ћ. ќ“—≈„≈Ќ»≈ «јƒЌ»’ √–јЌ≈… 
	glEnable (GL_CULL_FACE); // ¬ключаем отсечение граней 
	glCullFace (GL_BACK); // ”казываем, что отсекать будем задние грани	

	updateScreenSize();
	
	// Init fonts
	glEnable(GL_BLEND);
	setBlendFunc(getDefaultBlendFuncS(), getDefaultBlendFuncD());
	

	standart14Normal = FontCache::getInstance()->load("standart_14_normal");
	console8Normal = FontCache::getInstance()->load("console_8_normal");
	
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	
	
	GLenum err = glGetError ();
	if (GL_NO_ERROR != err)
		Log::error("GraphicEngine::initGL(): OpenGL Error: %s", gluErrorString (err));
	
	Log::info("OpenGL initialized");
	  
}
示例#12
0
bool GameScene::init() {
    Scene = this;
    
    ShaderLayer::init("shaders/vignette.glsl");
    
    rendTexSprite->getGLProgramState()->setUniformVec2("darkness", Vec2(1,1));
    
    mGame = new GameLogic(this);
    mGame->mWinGameEvent = [this]{onWinGame();};
    createControlPad();
    createMenuButtons();
    
#if 0
    Rect r = VisibleRect::getVisibleRect();
    
    Size sz(r.size);
    auto testsp = Sprite::create();
    testsp->setContentSize(sz);
    testsp->setTag(1024);
    
    testsp->setTexture(renderTextureBlur->getSprite()->getTexture());
    addChild(testsp,5000);
    
    r.size = sz;
    testsp->setTextureRect(r);
    
    auto ruv = r;
    ruv.size = renderTexture->getSprite()->getTexture()->getContentSizeInPixels() / 4;
    testsp->setPosition(VisibleRect::center());
    testsp->setFlippedY(true);
    testsp->setTextureCoords(ruv);
    //testsp->addEffect(EffectBloom::create(), 1);
    //testsp->addEffect(EffectBlur::create(), 2);
    
    testsp->setBlendFunc({GL_ONE,GL_ONE});
    //auto visibleRect = VisibleRect::getVisibleRect();
    //testsp->setScale(visibleRect.size.width / sz.width, visibleRect.size.height / sz.height);
#endif
    
    return true;
}
示例#13
0
void LayerTestBlend::newBlend(float dt)
{
     auto layer = (LayerColor*)getChildByTag(kTagLayer);

    GLenum src;
    GLenum dst;

    if( layer->getBlendFunc().dst == GL_ZERO )
    {
        src = GL_SRC_ALPHA;
        dst = GL_ONE_MINUS_SRC_ALPHA;
    }
    else
    {
        src = GL_ONE_MINUS_DST_COLOR;
        dst = GL_ZERO;
    }

    BlendFunc bf = {src, dst};
    layer->setBlendFunc( bf );
}
示例#14
0
LayerExtendedBlendOpacityTest::LayerExtendedBlendOpacityTest()
{
    auto layer1 = LayerGradient::create(Color4B(255, 0, 0, 255), Color4B(255, 0, 255, 255));
    layer1->setContentSize(Size(80, 80));
    layer1->setPosition(Vec2(50,50));
    addChild(layer1);
    
    auto layer2 = LayerGradient::create(Color4B(0, 0, 0, 127), Color4B(255, 255, 255, 127));
    layer2->setContentSize(Size(80, 80));
    layer2->setPosition(Vec2(100,90));
    addChild(layer2);
    
    auto layer3 = LayerGradient::create();
    layer3->setContentSize(Size(80, 80));
    layer3->setPosition(Vec2(150,140));
    layer3->setStartColor(Color3B(255, 0, 0));
    layer3->setEndColor(Color3B(255, 0, 255));
    layer3->setStartOpacity(255);
    layer3->setEndOpacity(255);
    layer3->setBlendFunc( BlendFunc::ALPHA_NON_PREMULTIPLIED );
    addChild(layer3);
}
示例#15
0
void COpenGLCacheHandler::setBlendFuncSeparate(GLenum sourceRGB, GLenum destinationRGB, GLenum sourceAlpha, GLenum destinationAlpha)
{
    if (sourceRGB != sourceAlpha || destinationRGB != destinationAlpha)
    {
        if (BlendSourceRGB[0] != sourceRGB || BlendDestinationRGB[0] != destinationRGB ||
            BlendSourceAlpha[0] != sourceAlpha || BlendDestinationAlpha[0] != destinationAlpha)
        {
            Driver->extGlBlendFuncSeparate(sourceRGB, destinationRGB, sourceAlpha, destinationAlpha);

            for (GLuint i = 0; i < FrameBufferCount; ++i)
            {
                BlendSourceRGB[i] = sourceRGB;
                BlendDestinationRGB[i] = destinationRGB;
                BlendSourceAlpha[i] = sourceAlpha;
                BlendDestinationAlpha[i] = destinationAlpha;
            }
        }
    }
    else
    {
        setBlendFunc(sourceRGB, destinationRGB);
    }
}
示例#16
0
void CCParticleBatchNode::addChild(CCNode * child, int zOrder, int tag)
{
    CCAssert( child != NULL, "Argument must be non-NULL");
    CCAssert( dynamic_cast<CCParticleSystem*>(child) != NULL, "CCParticleBatchNode only supports CCQuadParticleSystems as children");
    CCParticleSystem* pChild = (CCParticleSystem*)child;
    CCAssert( pChild->getTexture()->getName() == m_pTextureAtlas->getTexture()->getName(), "CCParticleSystem is not using the same texture id");
    // If this is the 1st children, then copy blending function
    if( m_pChildren->count() == 0 ) 
    {
        setBlendFunc(pChild->getBlendFunc());
    }

    CCAssert( m_tBlendFunc.src  == pChild->getBlendFunc().src && m_tBlendFunc.dst  == pChild->getBlendFunc().dst, "Can't add a PaticleSystem that uses a different blending function");

    //no lazy sorting, so don't call super addChild, call helper instead
    unsigned int pos = addChildHelper(pChild,zOrder,tag);

    //get new atlasIndex
    unsigned int atlasIndex = 0;

    if (pos != 0) 
    {
        CCParticleSystem* p = (CCParticleSystem*)m_pChildren->objectAtIndex(pos-1);
        atlasIndex = p->getAtlasIndex() + p->getTotalParticles();

    }
    else
    {
        atlasIndex = 0;
    }

    insertChild(pChild, atlasIndex);

    // update quad info
    pChild->setBatchNode(this);
}
示例#17
0
void FSprite::InitShader(const std::string& alpha_file)
{
#ifdef ETC1
    //Shader
    GLProgram* glp = new GLProgram();
    glp->autorelease();
    
    glp->initWithFilenames("testv.vsh", "test.fsh");
    glp->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_POSITION, GLProgram::VERTEX_ATTRIB_POSITION);
    glp->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_COLOR, GLProgram::VERTEX_ATTRIB_COLOR);
    glp->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_TEX_COORD, GLProgram::VERTEX_ATTRIB_TEX_COORD);
    glp->link();
    glp->updateUniforms();
    
    opacity_location_ = glGetUniformLocation(glp->getProgram(), "u_opacity");
    
    current_alpha_file_ = alpha_file;
    
//  #pragma message WARN("getTextureForKey or someth else, texture should be added on loading scene, do not add (cocos should check that anyway but still dont do it)  all the time!!")
    Texture2D* tex = Director::getInstance()->getTextureCache()->addImage(alpha_file);
	setBlendFunc(BlendFunc({ GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA }));
    //setBlendFunc((BlendFunc) { GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA });
    
    GLProgramState* glprogramstate = GLProgramState::getOrCreateWithGLProgram(glp);
    
    setGLProgramState(glprogramstate);
    
    glprogramstate->setUniformFloat(opacity_location_, (float)getOpacity()/255.0);
    
    glprogramstate->setUniformTexture("u_texture1", tex);
    

    
    setGLProgram(glp);
#endif
}
示例#18
0
    virtual bool init() override
    {
        this->Layer::init();
        Resource::Load();

        auto director = cocos2d::Director::getInstance();
        auto visibleSize = director->getVisibleSize();
        auto background = cocos2d::Sprite::create(Resource::WELCOME_BACKGROUND);
        auto newGame = cocos2d::ui::Button::create(Resource::BUTTON_NEWGAME);
        auto logoMaples = cocos2d::Sprite::create(Resource::LOGO_MAPLE);

        this->player = Fighter::Create(cocos2d::Point(visibleSize.width * 0.2, visibleSize.height * 0.2));

        logoMaples->setPosition(cocos2d::Point(visibleSize.width * 0.5, visibleSize.height * 0.7));
        logoMaples->setBlendFunc(cocos2d::BlendFunc::ADDITIVE);

        background->setPosition(cocos2d::Point::ZERO);
        background->setAnchorPoint(cocos2d::Point::ZERO);

        newGame->setPosition(cocos2d::Point(visibleSize.width * 0.5, visibleSize.height * 0.5));
        newGame->addTouchEventListener([this, director](cocos2d::Ref * pSender, cocos2d::ui::Widget::TouchEventType type){
            if (type == cocos2d::ui::Widget::TouchEventType::ENDED)
            {

                auto stepOne = cocos2d::CallFunc::create([this]
                {
                    this->addChild(Effect::CreateFlare());
                });

                auto stepTwo = cocos2d::CallFunc::create([director]
                {
                    auto transition = cocos2d::TransitionFade::create(2.0, HelloWorld::createScene());
                    director->replaceScene(transition);
                });

                this->runAction(cocos2d::Sequence::create(stepOne, stepTwo, nullptr));

            }
        });

        auto moveToRight = cocos2d::MoveTo::create(2.0, cocos2d::Vec2(visibleSize.width * 0.2, visibleSize.height * 0.2));
        auto moveToLeft = cocos2d::MoveTo::create(2.0, cocos2d::Vec2(visibleSize.width * 0.8, visibleSize.height * 0.2));

        auto sequence = cocos2d::Sequence::create(moveToLeft, moveToRight, nullptr);
        auto playerAction = cocos2d::RepeatForever::create(sequence);

        this->player->runAction(playerAction);

        auto name = cocos2d::Label::create();
        name->setString("姓名 : 刘枫林 (Maples)");
        name->setPosition(cocos2d::Point(visibleSize.width * 0.5, visibleSize.height * 0.36));
        auto info = cocos2d::Label::create();
        info->setString("学号 : 2013060109005");
        info->setPosition(cocos2d::Point(visibleSize.width * 0.5, visibleSize.height * 0.3));

        this->addChild(background);
        this->addChild(this->player);
        this->addChild(logoMaples);
        this->addChild(newGame);
        this->addChild(name);
        this->addChild(info);


        this->scheduleUpdate();
        return true;
    }
Scene* Chapter9_8::createScene()
{
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
    auto winSize = Director::getInstance()->getWinSize();
    
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // create a scene
    // 'scene' is an autorelease object
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    auto scene = Scene::create();
    
    // add title
    auto label = LabelTTF::create("BillBoard", "Arial", 24);
    label->setPosition(Vec2(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2).x,
                       Vec2(origin.x+visibleSize.width/2, origin.y+visibleSize.height).y - 30);
    
    scene->addChild(label, -1);
    
    //add the menu item for back to main menu
    label = LabelTTF::create("MainMenu", "Arial", 24);
    auto menuItem = MenuItemLabel::create(label);
    menuItem->setCallback([&](cocos2d::Ref *sender) {
        Director::getInstance()->replaceScene(Chapter9::createScene());
    });
    auto menu = Menu::create(menuItem, nullptr);
    menu->setPosition( Vec2::ZERO );
    menuItem->setPosition( Vec2(origin.x+visibleSize.width - 80, origin.y + 25) );
    scene->addChild(menu, 1);
    
    
    auto layer3D=Layer::create();
    scene->addChild(layer3D,2);
    
    static std::vector<BillBoard*> _billboards;
    for (int i = -4; i < 4; ++i)
    {
        auto billboard = BillBoard::create("Blue_Front1.png");
        billboard->setScale(0.5f);
        billboard->setPosition3D(Vec3(i * 50, 0.0f, 0));
        billboard->setBlendFunc(cocos2d::BlendFunc::ALPHA_NON_PREMULTIPLIED);
        _billboards.push_back(billboard);
        layer3D->addChild(billboard);
    }
    
    for (int i = -4; i < 4; ++i)
    {
        auto billboard = BillBoard::create("Blue_Front1.png");
        billboard->setScale(0.5f);
        billboard->setPosition3D(Vec3(i * 50, 0.0f, -50));
        billboard->setBlendFunc(cocos2d::BlendFunc::ALPHA_NON_PREMULTIPLIED);
        _billboards.push_back(billboard);
        layer3D->addChild(billboard);
    }
    
    // add camera
    auto camera=Camera::createPerspective(60, (GLfloat)winSize.width/winSize.height, 1, 1000);
    camera->setCameraFlag(CameraFlag::USER1);// set camera flag
    camera->setPosition3D(Vec3(0, 150, 230));
    camera->lookAt(Vec3(0, 0, 0), Vec3(0,1,0));
    
    // create camera action
    auto action = MoveBy::create(3, Vec2(100, 0));
    auto actionrev = action->reverse();
    auto actionback = MoveBy::create(3, Vec2(-100, 0));
    auto actionbackrev = actionback->reverse();
    auto seq = Sequence::create( action, actionrev, actionback, actionbackrev, nullptr );
    
    // run camera action
    camera->runAction( RepeatForever::create(seq) );
    
    layer3D->addChild(camera);
    
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // set camera mask
    // when node's camera-mask & camer-flag result is true, the node is visible for this camera.
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    layer3D->setCameraMask(0x2);
    
    // add select menue
    auto label1 = LabelTTF::create("Point Oriented", "Arial", 24);
    auto item1 = MenuItemLabel::create(label1);
    item1->setCallback([&](cocos2d::Ref *sender) {
        for (auto& billboard : _billboards) {
            billboard->setMode(BillBoard::Mode::VIEW_POINT_ORIENTED);
        }
    });
    auto label2 = LabelTTF::create("Plane Oriented", "Arial", 24);
    auto item2 = MenuItemLabel::create(label2);
    item2->setCallback([&](cocos2d::Ref *sender) {
        for (auto& billboard : _billboards) {
            billboard->setMode(BillBoard::Mode::VIEW_PLANE_ORIENTED);
        }
    });
    auto itemSize = item1->getContentSize();
    item1->setPosition( Vec2(origin.x + 100, origin.y+visibleSize.height - itemSize.height * 2));
    item2->setPosition( Vec2(origin.x + 100, origin.y+visibleSize.height - itemSize.height * 3));
    
    auto menuSelect = CCMenu::create(item1, item2, NULL);
    menuSelect->setPosition(Vec2(0,0));
    scene->addChild(menuSelect, 1);
    
    // return the scene
    return scene;
}
示例#20
0
void GAFMovieClip::_setBlendingFunc()
{
    setBlendFunc(cocos2d::BlendFunc::ALPHA_PREMULTIPLIED);
}
示例#21
0
void GameResultSuccess::playTextFlash(void)
{
	return;
	auto StrSuc = (Sprite*)GameMainLayer::seekNodeByName(_myLayer, "StrSuc");
	auto strSucSize = StrSuc->getContentSize();

	auto imgFlash1 = Sprite::create("FirstUIRes/imgflash.png");
	auto imgFlash2 = Sprite::create("FirstUIRes/imgflash.png");
	auto imgFlash3 = Sprite::create("FirstUIRes/imgflash.png");
	auto imgFlash4 = Sprite::create("FirstUIRes/imgflash.png");
	imgFlash1->setScale(0.1f);
	imgFlash2->setScale(0.1f);
	imgFlash3->setScale(0.1f);
	imgFlash4->setScale(0.1f);

	imgFlash1->setBlendFunc(BlendFunc::ADDITIVE);
	imgFlash2->setBlendFunc(BlendFunc::ADDITIVE);
	imgFlash3->setBlendFunc(BlendFunc::ADDITIVE);
	imgFlash4->setBlendFunc(BlendFunc::ADDITIVE);
	imgFlash1->setPosition(Vec2(strSucSize.width*0.5, strSucSize.height*0.88));
	imgFlash2->setPosition(Vec2(strSucSize.width*0.05, strSucSize.height*0.3));
	imgFlash3->setPosition(Vec2(strSucSize.width*0.05, strSucSize.height*0.78));
	imgFlash4->setPosition(Vec2(strSucSize.width, strSucSize.height*0.85));
	StrSuc->addChild(imgFlash1);
	StrSuc->addChild(imgFlash2);
	StrSuc->addChild(imgFlash3);
	StrSuc->addChild(imgFlash4);

	auto action = Spawn::create(CCScaleTo::create(0.5, 1.0), CCFadeIn::create(0.5), nullptr);
	auto actionback = Spawn::create(CCScaleTo::create(0.5, 0.2), CCFadeOut::create(0.5), nullptr);
	imgFlash1->runAction(RepeatForever::create(Sequence::create(
		CCDelayTime::create(1.0f), Spawn::create(
		CCScaleTo::create(0.01, 0.2),
		CCFadeOut::create(0.01), nullptr),
		Spawn::create(CCScaleTo::create(0.5, 1.0), CCFadeIn::create(0.5), nullptr),
		Spawn::create(CCScaleTo::create(0.5, 0.2), CCFadeOut::create(0.5), nullptr),
		nullptr)));

	imgFlash2->runAction(RepeatForever::create(Sequence::create(
		CCDelayTime::create(1.2f), Spawn::create(
		CCScaleTo::create(0.01, 0.2),
		CCFadeOut::create(0.01), nullptr),
		Spawn::create(CCScaleTo::create(0.5, 0.3), CCFadeIn::create(0.5), nullptr),
		Spawn::create(CCScaleTo::create(0.5, 0.1), CCFadeOut::create(0.5), nullptr),
		nullptr)));

	imgFlash3->runAction(RepeatForever::create(Sequence::create(
		CCDelayTime::create(0.5f), Spawn::create(
		CCScaleTo::create(0.01, 0.1),
		CCFadeOut::create(0.01), nullptr),
		Spawn::create(CCScaleTo::create(0.5, 0.3), CCFadeIn::create(0.5), nullptr),
		Spawn::create(CCScaleTo::create(0.5, 0.1), CCFadeOut::create(0.5), nullptr),
		nullptr)));

	imgFlash4->runAction(RepeatForever::create(Sequence::create(
		CCDelayTime::create(1.8f), Spawn::create(
		CCScaleTo::create(0.01, 0.2),
		CCFadeOut::create(0.01), nullptr),
		Spawn::create(CCScaleTo::create(0.5, 0.3), CCFadeIn::create(0.5), nullptr),
		Spawn::create(CCScaleTo::create(0.5, 0.1), CCFadeOut::create(0.5), nullptr),
		nullptr)));
}
示例#22
0
void Fish::initphysicsBody()
{
    auto pbody = GameDataMgr::getInstance()->getBodyByType(m_data.nFishType);
    if (!pbody) {
        return;
    }
    pbody->setGravityEnable(false);
    pbody->setCategoryBitmask(1);
    pbody->setContactTestBitmask(2);
    pbody->setCollisionBitmask(0);
    this->setPhysicsBody(pbody);
    
    if (m_data.bSpecial || m_data.bKiller)
    {
        m_light = Sprite::createWithSpriteFrameName(__String::createWithFormat("fish_%d_yd_light_0.png",m_data.nFishType)->getCString());
        m_light->setPosition(this->getPosition());
        this->getParent()->addChild(m_light,m_data.nFishType);
        auto ligthanim = AnimationCache::getInstance()->getAnimation(__String::createWithFormat("fish_%d_yd_light", m_data.nFishType)->getCString());
        auto paction = RepeatForever::create(Animate::create(ligthanim));
        m_light->runAction(paction);
        BlendFunc blendFunc = {GL_SRC_ALPHA,GL_ONE};
        m_light->setBlendFunc(blendFunc);
        m_light->setScale(1.5f);
        
        auto plight = Sprite::createWithSpriteFrameName(__String::createWithFormat("fish_%d_yd_light_0.png",m_data.nFishType)->getCString());
        plight->setPosition(m_light->getContentSize()/2);
        plight->setBlendFunc(blendFunc);
        m_light->addChild(plight);
        
        if (m_data.bSpecial) {
            m_guan = Sprite::createWithSpriteFrameName(__String::createWithFormat("fish_%d_yd_crown.png", m_data.nFishType)->getCString());
            m_guan->setPosition(this->getContentSize()/2);
            this->addChild(m_guan);
            m_light->setColor(Color3B::YELLOW);
            plight->setColor(Color3B::YELLOW);
            
        }
        if (m_data.bKiller) {
            m_guan = Sprite::createWithSpriteFrameName(__String::createWithFormat("fish_%d_bomb_0.png", m_data.nFishType)->getCString());
            m_guan->setPosition(this->getContentSize()/2);
            this->addChild(m_guan);
            auto bombanim = AnimationCache::getInstance()->getAnimation(__String::createWithFormat("fish_%d_bomb", m_data.nFishType)->getCString());
            auto paction = RepeatForever::create(Animate::create(bombanim));
            m_guan->runAction(paction);
            m_light->setColor(Color3B(255, 0, 0));
            auto lightaction = TintBy::create(2.f, 0, 255, 0);
            auto lightaction1 = TintBy::create(2.f, 0, 0, 0);
            m_light->runAction(RepeatForever::create(Sequence::createWithTwoActions(lightaction, lightaction1)));
            
            plight->runAction(RepeatForever::create(Sequence::createWithTwoActions(lightaction->clone(), lightaction1->clone())));
            plight->setColor(Color3B(255, 0, 0));
            
            auto plight1 = Sprite::createWithSpriteFrameName(__String::createWithFormat("fish_%d_yd_light_0.png",m_data.nFishType)->getCString());
            plight1->setPosition(m_light->getContentSize()/2);
            plight1->setColor(Color3B(255, 0, 0));
            plight1->runAction(RepeatForever::create(Sequence::createWithTwoActions(lightaction->clone(), lightaction1->clone())));
            m_light->addChild(plight1);
        }
    }
    
    //this->setPhysicsBody(nullptr);
}
void VBModel::InitWithLibName(VBObjectFile2D* _obj2D, CCTexture2D* _texture, VBObjectFile2DLibraryNameID* _library_name_id, bool _is_realtime_animation, ccBlendFunc _blend) {
    init();
    
	use_mix_color = true;
    
    is_use_animation = true;
    is_play_loop = true;
    is_play = true;
    is_real_time_animation = _is_realtime_animation;
    frame_rate = VBObjectFile2DGetFrameRate(_obj2D);
    
    VBObjectFile2DLibrary* _library = VBObjectFile2DGetLibraryByNameID(_obj2D, _library_name_id);
    void* _library_base = VBObjectFile2DLibraryGetBase(_library);
    if(VBObjectFile2DLibraryType_Bitmap == VBObjectFile2DLibraryGetType(_library)) {
        is_bitmap = true;
        VBObjectFile2DLibraryBitmap* _bitmap = (VBObjectFile2DLibraryBitmap*)_library_base;
        
        VBULong _poly_len = VBObjectFile2DLibraryBitmapGetUVInfoLength(_bitmap);
        
        VBVector2D _txc[_poly_len];
        VBVector2D* _uv = VBObjectFile2DLibraryBitmapGetUVInfo(_bitmap);
        
        VBVector2D* _txc_ptr = _txc;
        
        for(int _i = 0; _i < _poly_len; _i++) {
            _txc_ptr->x = _uv[_i].x;
            _txc_ptr->y = _uv[_i].y;
            _txc_ptr++;
        }
		
		setTexture(_texture);
		CCRect _rect = CCRect(_txc[0].x * _texture->getPixelsWide(),
							  _txc[0].y * _texture->getPixelsHigh(),
							  (_txc[2].x * _texture->getPixelsWide() - _txc[0].x * _texture->getPixelsWide()),
							  (_txc[2].y  * _texture->getPixelsHigh() - _txc[0].y * _texture->getPixelsHigh()));
        cocos2d::CCSprite::setTextureRect(CC_RECT_POINTS_TO_PIXELS(_rect));

//        cocos2d::CCSprite::setTextureRect(CCRect(_txc[0].x * _texture->getPixelsWide() / CCDirector::sharedDirector()->getContentScaleFactor(),
//							  _txc[0].y * _texture->getPixelsHigh() / CCDirector::sharedDirector()->getContentScaleFactor(),
//							  (_txc[2].x * _texture->getPixelsWide() - _txc[0].x * _texture->getPixelsWide()) / CCDirector::sharedDirector()->getContentScaleFactor(),
//							  (_txc[2].y  * _texture->getPixelsHigh() - _txc[0].y * _texture->getPixelsHigh()) / CCDirector::sharedDirector()->getContentScaleFactor())
//					   );
    } else if(VBObjectFile2DLibraryType_Graphic == VBObjectFile2DLibraryGetType(_library) || VBObjectFile2DLibraryType_MovieClip == VBObjectFile2DLibraryGetType(_library)) {
        frame_all_allocated_child_models = VBArrayVectorInit(VBArrayVectorAlloc());
        frame_willFree_child_models = VBArrayVectorInit(VBArrayVectorAlloc());
        frame_current_key_frame = VBArrayVectorInit(VBArrayVectorAlloc());
        
        if(VBObjectFile2DLibraryType_Graphic == VBObjectFile2DLibraryGetType(_library)) {
            VBObjectFile2DLibraryGraphic* _graphic = (VBObjectFile2DLibraryGraphic*)_library_base;
            frame = VBObjectFile2DLibraryGraphicGetFrame(_graphic);
        } else if(VBObjectFile2DLibraryType_MovieClip == VBObjectFile2DLibraryGetType(_library)) {
            VBObjectFile2DLibraryMovieClip* _movie_clip = (VBObjectFile2DLibraryMovieClip*)_library_base;
            frame = VBObjectFile2DLibraryMovieClipGetFrame(_movie_clip);
        }
        
        is_play = VBTrue;
        is_play_loop = VBTrue;
        is_animation_update = VBTrue;
        
        while (frame_all_allocated_child_models->len < frame->key_frame->len) {
            VBArrayVectorAddBack(frame_all_allocated_child_models, NULL);
        }
        for(int i = 0; i < frame->key_frame->len; i++) {
            VBObjectFile2DKeyFrame* _key_frame = (VBObjectFile2DKeyFrame*)frame->key_frame->data[i];
            if(frame_all_allocated_child_models->data[i] == NULL) {
                VBModel* _child = new VBModel(_obj2D, _texture, _key_frame->library_id, _is_realtime_animation, _blend);
                frame_all_allocated_child_models->data[i] = _child;
                VBArrayVectorAddBack(frame_willFree_child_models, _child);
                LinkChildKeyFrames(i, _child, _key_frame);
            }
        }
    }
    Update(0.0f);
	setBlendFunc(_blend);
}