Ejemplo n.º 1
0
CCSkin *CCSkin::create(const char *pszFileName)
{
	CCSkin *skin = new CCSkin();
	if(skin && skin->initWithFile(pszFileName))
	{
		skin->autorelease();
		return skin;
	}
	CC_SAFE_DELETE(skin);
	return NULL;
}
Ejemplo n.º 2
0
void CCDisplayFactory::createSpriteDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay)
{
    CCSkin *skin = NULL;

    CCSpriteDisplayData *displayData = (CCSpriteDisplayData *)decoDisplay->getDisplayData();

    std::string textureName = displayData->displayName;
    size_t startPos = textureName.find_last_of(".");

    if(startPos != std::string::npos)
    {
        textureName = textureName.erase(startPos);
    }

    //! create display
    if(textureName.length() == 0)
    {
        skin = CCSkin::create();
    }
    else
    {
        skin = CCSkin::createWithSpriteFrameName((textureName + ".png").c_str());
    }

    decoDisplay->setDisplay(skin);

    if (skin == NULL)
    {
        return;
    }

    skin->setBone(bone);

    initSpriteDisplay(bone, decoDisplay, displayData->displayName.c_str(), skin);

    CCArmature *armature = bone->getArmature();
    if (armature)
    {
        if (armature->getArmatureData()->dataVersion >= VERSION_COMBINED)
        {
            skin->setSkinData(displayData->skinData);
        }
        else
        {
            skin->setSkinData(*bone->getBoneData());
        }
    }
}
Ejemplo n.º 3
0
NS_CC_EXT_BEGIN

#if CC_SPRITEBATCHNODE_RENDER_SUBPIXEL
#define RENDER_IN_SUBPIXEL
#else
#define RENDER_IN_SUBPIXEL(__ARGS__) (ceil(__ARGS__))
#endif

CCSkin *CCSkin::create()
{
    CCSkin *skin = new CCSkin();
    if(skin && skin->init())
    {
        skin->autorelease();
        return skin;
    }
    CC_SAFE_DELETE(skin);
    return NULL;
}
Ejemplo n.º 4
0
void CCDisplayFactory::createSpriteDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay)
{
    CCSkin *skin = NULL;

    CCSpriteDisplayData *displayData = (CCSpriteDisplayData *)decoDisplay->getDisplayData();

    std::string textureName = displayData->displayName;

    //! create display
    if(textureName.length() == 0)
    {
        skin = CCSkin::create();
    }
    else
    {
        skin = CCSkin::createWithSpriteFrameName((textureName + ".png").c_str());
    }

    skin->setBone(bone);
    skin->setFlipX(displayData->flipX);
    
    initSpriteDisplay(bone, decoDisplay, displayData->displayName.c_str(), skin);

    CCArmature *armature = bone->getArmature();
    if (armature)
    {
        if (armature->getArmatureData()->dataVersion >= VERSION_COMBINED)
        {
            skin->setSkinData(displayData->skinData);
        }
        else
        {
            skin->setSkinData(*bone->getBoneData());
        }
    }

    decoDisplay->setDisplay(skin);

}
Ejemplo n.º 5
0
void CCDisplayFactory::updateSpriteDisplay(CCBone *bone, CCNode *display, float dt, bool dirty)
{
    CS_RETURN_IF(!dirty);
    CCSkin *skin = (CCSkin *)display;
    skin->updateArmatureTransform();
}
Ejemplo n.º 6
0
void CBArmature::draw()
{
    if(m_preDrawFunction)
        m_preDrawFunction->execute();
    
    if (m_pParentBone == NULL && m_pBatchNode == NULL)
    {
        CC_NODE_DRAW_SETUP();
        ccGLBlendFunc(m_sBlendFunc.src, m_sBlendFunc.dst);
    }
    
    CCObject *object = NULL;
    CCARRAY_FOREACH(m_pChildren, object)
    {
        if (CCBone *bone = dynamic_cast<CCBone *>(object))
        {
            CCNode *node = bone->getDisplayRenderNode();
            
            if (NULL == node)
                continue;
            
            switch (bone->getDisplayRenderNodeType())
            {
                case CS_DISPLAY_SPRITE:
                {
                    CCSkin *skin = (CCSkin *)node;
                    
                    CCTextureAtlas *textureAtlas = skin->getTextureAtlas();
                    bool blendDirty = bone->isBlendDirty();
                    if(m_pAtlas != textureAtlas || blendDirty)
                    {
                        if (m_pAtlas)
                        {
                            if(CBTextureAtlas* pAtlas = dynamic_cast<CBTextureAtlas *>(m_pAtlas)) {
                                pAtlas->drawQuadsEx();
                            } else {
                                m_pAtlas->drawQuads();
                            }
                            m_pAtlas->removeAllQuads();
                        }
                    }
                    
                    m_pAtlas = textureAtlas;
                    if (m_pAtlas->getCapacity() == m_pAtlas->getTotalQuads() && !m_pAtlas->resizeCapacity(m_pAtlas->getCapacity() * 2))
                        return;
                    
                    skin->updateTransform();
                    
                    if (blendDirty)
                    {
                        ccBlendFunc func = bone->getBlendFunc();
                        ccGLBlendFunc(func.src, func.dst);
                        
                        if(CBTextureAtlas* pAtlas = dynamic_cast<CBTextureAtlas *>(m_pAtlas)) {
                            pAtlas->drawQuadsEx();
                        } else {
                            m_pAtlas->drawQuads();
                        }
                        m_pAtlas->removeAllQuads();
                        
                        ccGLBlendFunc(m_sBlendFunc.src, m_sBlendFunc.dst);
                        bone->setBlendDirty(false);
                    }
                }
                    break;
                case CS_DISPLAY_ARMATURE:
                {
                    CCArmature *armature = (CCArmature *)(node);
                    
                    CCTextureAtlas *textureAtlas = armature->getTextureAtlas();
                    if(m_pAtlas != textureAtlas)
                    {
                        if (m_pAtlas)
                        {
                            if(CBTextureAtlas* pAtlas = dynamic_cast<CBTextureAtlas *>(m_pAtlas)) {
                                pAtlas->drawQuadsEx();
                            } else {
                                m_pAtlas->drawQuads();
                            }
                            m_pAtlas->removeAllQuads();
                        }
                    }
                    armature->draw();
                    
                    m_pAtlas = armature->getTextureAtlas();
                }
                    break;
                default:
                {
                    if (m_pAtlas)
                    {
                        if(CBTextureAtlas* pAtlas = dynamic_cast<CBTextureAtlas *>(m_pAtlas)) {
                            pAtlas->drawQuadsEx();
                        } else {
                            m_pAtlas->drawQuads();
                        }
                        m_pAtlas->removeAllQuads();
                    }
                    node->visit();
                    
                    CC_NODE_DRAW_SETUP();
                    ccGLBlendFunc(m_sBlendFunc.src, m_sBlendFunc.dst);
                }
                    break;
            }
        }
        else if(CCNode *node = dynamic_cast<CCNode *>(object))
        {
            if (m_pAtlas)
            {
                if(CBTextureAtlas* pAtlas = dynamic_cast<CBTextureAtlas *>(m_pAtlas)) {
                    pAtlas->drawQuadsEx();
                } else {
                    m_pAtlas->drawQuads();
                }
                m_pAtlas->removeAllQuads();
            }
            node->visit();
            
            CC_NODE_DRAW_SETUP();
            ccGLBlendFunc(m_sBlendFunc.src, m_sBlendFunc.dst);
        }
    }
    
    if(m_pAtlas && !m_pBatchNode && m_pParentBone == NULL)
    {
        if(CBTextureAtlas* pAtlas = dynamic_cast<CBTextureAtlas *>(m_pAtlas)) {
            pAtlas->drawQuadsEx();
        } else {
            m_pAtlas->drawQuads();
        }
        m_pAtlas->removeAllQuads();
    }
}