예제 #1
0
파일: Sprite.cpp 프로젝트: vHanda/Survival
//TODO: Optimize this ..
void Sprite::init(TiXmlElement * pElement)
{
    if(pElement->ValueStr() != "sprite")
        return;

    TiXmlAttribute * pAtt = pElement->FirstAttribute();
    setFPS( pAtt->IntValue() );

    TiXmlElement * pChild = pElement->FirstChildElement();
    while(pChild != NULL)
    {
        if(pChild->ValueStr() != "surface")
            continue;

        std::string fileName = pChild->GetText();
        SDL_SurfacePtr pSurface = load_image(fileName);
        float zoom = 1.0f;
        float rot = 0.0f;
        float alpha = 1.0;

        TiXmlAttribute * pAttrib = pChild->FirstAttribute();
        if(pAttrib != NULL)
        {
            SDL_Rect rect = {-1,-1,-1,-1};
            while(pAttrib != NULL)
            {
                //std::cout << pAttrib->Name() << std::endl;
                if(pAttrib->Name() == std::string("x"))
                    rect.x = pAttrib->IntValue();
                else if(pAttrib->Name() == std::string("y"))
                    rect.y = pAttrib->IntValue();
                else if(pAttrib->Name() == std::string("w"))
                    rect.w = pAttrib->IntValue();
                else if(pAttrib->Name() == std::string("h"))
                    rect.h = pAttrib->IntValue();
                else if(pAttrib->Name() == std::string("rot"))
                    rot = pAttrib->DoubleValue();
                else if(pAttrib->Name() == std::string("zoom"))
                    zoom = pAttrib->DoubleValue();
                else if(pAttrib->Name() == std::string("alpha"))
                    alpha = pAttrib->DoubleValue();

                pAttrib = pAttrib->Next();
            }
            if( rect.x != -1 && rect.y != -1 && rect.w != -1 && rect.h != -1)
                pSurface = getSurface( pSurface.get(), rect );
            if( zoom != 1.0 || rot != 0.0f )
                pSurface = rotozoomSurface( pSurface.get(), rot, zoom, 1); //1 is for smoothing
            if( alpha != 1.0 )
            {
                int a = 255*alpha;
                SDL_SetAlpha( pSurface.get(), SDL_SRCALPHA|SDL_RLEACCEL, a);
            }
        }

        m_Sprites.push_back( new SDL_SurfacePtr(pSurface) );
        pChild = pChild->NextSiblingElement();
    }
}
예제 #2
0
파일: App.cpp 프로젝트: vHanda/DigitRecog
void App::additional_init()
{
    m_State = state_loading;

    Font font("Ayu.ttf", 70);
    std::string s = "Training the Brain\nPlease Wait ...";
    SDL_SurfacePtr surf = font.render_Blended(s);
    m_LoadingImage.load( surf.get() );
}
예제 #3
0
bool operator !=(const SDL_SurfacePtr & lhs, const SDL_SurfacePtr & rhs)
{ return lhs.get() != rhs.get(); }