Ejemplo n.º 1
0
TextureSystem::TextureSystem(sf::RenderWindow& rw, entityx::EntityManager& entities, KeyValue& keys)
    : window(rw)
    , imageRenderEnabled(false)
    , randomTexturesEnabled(true)
    , positionTextEnabled(false)
    , entities(entities)
{
    /* This doesn't change. It maps the type shape to the vector of textures aviliable
     * under random texturing, or we use the first for no random textures */
    texturemap = {
        {    SpawnComponent::BOX, {&boxTextures,  conf::box_halfwidth*2}},
        { SpawnComponent::CIRCLE, {&ballTextures, conf::circle_radius*2}}
    };

    /* Textures for physics objects
     * `loadTextures` reads a key from an .ini consisting of colon-delimited
     * textures, and loads them into a vector */
    loadTextures(boxTextures,  keys.GetString("BOX_TEXTURES"));
    loadTextures(ballTextures, keys.GetString("BALL_TEXTURES"));

    //Load background texture and make it repeating
    bgTexture.loadFromFile(keys.GetString("BACKGROUND_TEXTURE"));
    bgTexture.setRepeated(true);
    bgSprite.setTexture(bgTexture);
    auto windsz = rw.getSize();
    bgSprite.setTextureRect(sf::IntRect(0, 0, windsz.x, windsz.y));

    //Font for displaying positions and other things
    boxFont.loadFromFile(keys.GetString("OBJECT_FONT"));
}