Esempio n. 1
0
void Sprite::setBatchNode(SpriteBatchNode *spriteBatchNode)
{
    _batchNode = spriteBatchNode; // weak reference

    // self render
    if( ! _batchNode ) {
        _atlasIndex = INDEX_NOT_INITIALIZED;
        setTextureAtlas(nullptr);
        _recursiveDirty = false;
        setDirty(false);

        float x1 = _offsetPosition.x;
        float y1 = _offsetPosition.y;
        float x2 = x1 + _rect.size.width;
        float y2 = y1 + _rect.size.height;
        _quad.bl.vertices.set( x1, y1, 0 );
        _quad.br.vertices.set(x2, y1, 0);
        _quad.tl.vertices.set(x1, y2, 0);
        _quad.tr.vertices.set(x2, y2, 0);

    } else {

        // using batch
        _transformToBatch = Mat4::IDENTITY;
        setTextureAtlas(_batchNode->getTextureAtlas()); // weak ref
    }
}
Esempio n. 2
0
    std::shared_ptr<Button> Canvas::createButton(std::string text) {
        std::shared_ptr<TextureAtlas> textureAtlas = Project::loadTextureAtlas("assets/ui/ui.txt");
        auto button = addComponent<Button>();

        button->setTextureAtlas(textureAtlas);
        button->setNormalSprite("button-normal.png");
        button->setHoverSprite("button-hover.png");
        button->setPressedSprite("button-pressed.png");
        button->setScale({2,2});
        button->setText(text);

        return button;
    }
Esempio n. 3
0
bool Skin::initWithFile(const char *pszFilename)
{
    bool ret = Sprite::initWithFile(pszFilename);

    if (ret)
    {
		TextureAtlas *atlas = SpriteFrameCacheHelper::getInstance()->getTexureAtlasWithTexture(_texture);
		setTextureAtlas(atlas);

		_displayName = pszFilename;
    }

    return ret;
}
Esempio n. 4
0
bool CCAtlasNode::initWithTileFile(const char *tile, unsigned int tileWidth, unsigned int tileHeight,
                                   unsigned int itemsToRender)
{
    CCAssert(tile != NULL, "title should not be null");
    m_uItemWidth  = tileWidth;
    m_uItemHeight = tileHeight;

    m_cOpacity = 255;
    m_tColor = m_tColorUnmodified = ccWHITE;
    m_bIsOpacityModifyRGB = true;

    m_tBlendFunc.src = CC_BLEND_SRC;
    m_tBlendFunc.dst = CC_BLEND_DST;

    CCTextureAtlas* pNewAtlas= new CCTextureAtlas();
    pNewAtlas->initWithFile(tile, itemsToRender);
    setTextureAtlas(pNewAtlas);
    pNewAtlas->release();

    if (! m_pTextureAtlas)
    {
        CCLOG("cocos2d: Could not initialize CCAtlasNode. Invalid Texture.");
        return false;
    }

    this->updateBlendFunc();
    this->updateOpacityModifyRGB();

    this->calculateMaxItems();

    m_uQuadsToDraw = itemsToRender;

    // shader stuff
    setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTexture_uColor));
    m_nUniformColor = glGetUniformLocation( getShaderProgram()->getProgram(), "u_color");

    return true;
}
Esempio n. 5
0
 std::shared_ptr<Sprite> Canvas::createSprite(std::shared_ptr<TextureAtlas> textureAtlas, std::string spriteName, glm::vec2 pos) {
     auto sprite = addComponent<Sprite>();
     sprite->setTextureAtlas(textureAtlas);
     sprite->setSpriteName(spriteName);
     return sprite;
 }