void BatchNodeBase::updateBlendFunc(cocos2d::Texture2D *tex) { if (tex) { auto glProgramName = getGLProgram()->getProgram(); auto pixelFormat = tex->getPixelFormat(); cocos2d::GLProgramState *newState = nullptr; if (pixelFormat == cocos2d::Texture2D::PixelFormat::A8) { newState = getProgramStateA8(); } else if (pixelFormat == cocos2d::Texture2D::PixelFormat::I8) { newState = getProgramStateI8(); } else if (pixelFormat == cocos2d::Texture2D::PixelFormat::AI88) { newState = getProgramStateAI88(); } else { newState = getProgramStateFullColor(); } if (newState->getGLProgram()->getProgram() != glProgramName) { setGLProgramState(newState); } if (!tex->hasPremultipliedAlpha()) { _blendFunc = cocos2d::BlendFunc::ALPHA_NON_PREMULTIPLIED; setOpacityModifyRGB(false); } else { _blendFunc = cocos2d::BlendFunc::ALPHA_PREMULTIPLIED; setOpacityModifyRGB(true); } } }
void SpriteBatchNode::updateBlendFunc() { if (! _textureAtlas->getTexture()->hasPremultipliedAlpha()) { _blendFunc = BlendFunc::ALPHA_NON_PREMULTIPLIED; setOpacityModifyRGB(false); } else { _blendFunc = BlendFunc::ALPHA_PREMULTIPLIED; setOpacityModifyRGB(true); } }
void Scale9Sprite::updateBlendFunc(Texture2D *texture) { // it is possible to have an untextured sprite if (! texture || ! texture->hasPremultipliedAlpha()) { _blendFunc = BlendFunc::ALPHA_NON_PREMULTIPLIED; setOpacityModifyRGB(false); } else { _blendFunc = BlendFunc::ALPHA_PREMULTIPLIED; setOpacityModifyRGB(true); } }
void Sprite::updateBlendFunc() { CCASSERT(! _batchNode, "CCSprite: updateBlendFunc doesn't work when the sprite is rendered using a SpriteBatchNode"); // it is possible to have an untextured sprite if (_texture == nullptr || ! _texture->hasPremultipliedAlpha()) { _blendFunc = BlendFunc::ALPHA_NON_PREMULTIPLIED; setOpacityModifyRGB(false); } else { _blendFunc = BlendFunc::ALPHA_PREMULTIPLIED; setOpacityModifyRGB(true); } }
void SkeletonRenderer::initialize () { _worldVertices = new float[1000]; // Max number of vertices per mesh. _blendFunc = BlendFunc::ALPHA_PREMULTIPLIED; setOpacityModifyRGB(true); setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP)); }
void CCSkeleton::initialize () { atlas = 0; debugSlots = false; debugBones = false; timeScale = 1; blendFunc = BlendFunc::ALPHA_PREMULTIPLIED; setOpacityModifyRGB(true); setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); scheduleUpdate(); }
bool MyControlButton::initWithLabelAndBackgroundSprite(Node* node, ui::Scale9Sprite* backgroundSprite,bool isSallowTouch) { if (init(isSallowTouch)) { CCASSERT(node != nullptr, "node must not be nil."); LabelProtocol* label = dynamic_cast<LabelProtocol*>(node); CCASSERT(backgroundSprite != nullptr, "Background sprite must not be nil."); CCASSERT(label != nullptr, "label must not be nil."); _parentInited = true; _isPushed = false; // Adjust the background image by default setAdjustBackgroundImage(true); setPreferredSize(Size::ZERO); // Zooming button by default _zoomOnTouchDown = true; _scaleRatio = 1.1f; // Set the default anchor point ignoreAnchorPointForPosition(false); setAnchorPoint(Vec2::ANCHOR_MIDDLE); // Set the nodes setTitleLabel(node); setBackgroundSprite(backgroundSprite); // Set the default color and opacity setColor(Color3B::WHITE); setOpacity(255.0f); setOpacityModifyRGB(true); // Initialize the dispatch table setTitleForState(label->getString(), Control::State::NORMAL); setTitleColorForState(node->getColor(), Control::State::NORMAL); setTitleLabelForState(node, Control::State::NORMAL); setBackgroundSpriteForState(backgroundSprite, Control::State::NORMAL); setLabelAnchorPoint(Vec2::ANCHOR_MIDDLE); // Layout update needsLayout(); return true; } //couldn't init the Control else { return false; } }
void CCSkeleton::initialize () { atlas = 0; debugSlots = false; debugBones = false; timeScale = 1; blendFunc.src = GL_ONE; blendFunc.dst = GL_ONE_MINUS_SRC_ALPHA; setOpacityModifyRGB(true); setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor)); scheduleUpdate(); }
void Skeleton::initialize () { atlas = 0; debugSlots = false; debugBones = false; timeScale = 1; blendFunc.src = BlendFunc::ALPHA_PREMULTIPLIED.src; blendFunc.dst = BlendFunc::ALPHA_PREMULTIPLIED.dst; setOpacityModifyRGB(true); setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); }
void CCSkeleton::initialize () { atlas = 0; debugSlots = false; debugBones = false; timeScale = 1; blendFunc.src = GL_ONE; blendFunc.dst = GL_ONE_MINUS_SRC_ALPHA; setOpacityModifyRGB(true); setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor)); // JRW - This should NOT be done automatically...the // owner of the skeleton should call it. // scheduleUpdate(); }
void TextureSprite::updateBlendFunc() { m_sBlendFunc.src = CC_BLEND_SRC; m_sBlendFunc.dst = CC_BLEND_DST; setOpacityModifyRGB(true); }
bool ark_SwallowButton::init() { if (Layer::init()) { // Initialise instance variables _state=Control::State::NORMAL; setEnabled(true); setSelected(false); setHighlighted(false); auto dispatcher = Director::getInstance()->getEventDispatcher(); auto touchListener = EventListenerTouchOneByOne::create(); touchListener->setSwallowTouches(true); touchListener->onTouchBegan = CC_CALLBACK_2(Control::onTouchBegan, this); touchListener->onTouchMoved = CC_CALLBACK_2(Control::onTouchMoved, this); touchListener->onTouchEnded = CC_CALLBACK_2(Control::onTouchEnded, this); touchListener->onTouchCancelled = CC_CALLBACK_2(Control::onTouchCancelled, this); dispatcher->addEventListenerWithSceneGraphPriority(touchListener, this); Scale9Sprite * backgroundSprite = Scale9Sprite::create(); Label *node = Label::createWithSystemFont("", "Helvetica", 12); CCASSERT(node != nullptr, "Label must not be nil."); LabelProtocol* label = dynamic_cast<LabelProtocol*>(node); CCASSERT(backgroundSprite != nullptr, "Background sprite must not be nil."); CCASSERT(label != nullptr || backgroundSprite != nullptr, ""); _parentInited = true; _isPushed = false; // Adjust the background image by default setAdjustBackgroundImage(true); setPreferredSize(Size::ZERO); // Zooming button by default _zoomOnTouchDown = true; _scaleRatio = 1.1f; // Set the default anchor point ignoreAnchorPointForPosition(false); setAnchorPoint(Point(0.5f, 0.5f)); // Set the nodes setTitleLabel(node); setBackgroundSprite(backgroundSprite); // Set the default color and opacity setColor(Color3B(255.0f, 255.0f, 255.0f)); setOpacity(255.0f); setOpacityModifyRGB(true); // Initialize the dispatch table setTitleForState(label->getString(), Control::State::NORMAL); setTitleColorForState(node->getColor(), Control::State::NORMAL); setTitleLabelForState(node, Control::State::NORMAL); setBackgroundSpriteForState(backgroundSprite, Control::State::NORMAL); setLabelAnchorPoint(Point(0.5f, 0.5f)); // Layout update needsLayout(); return true; } else { return false; } }