Game Development Reference
In-Depth Information
{
auto sprite = std::make_shared<Sprite>();
auto tex = _texCache[path];
if (tex == nullptr)
{
tex = std::make_shared<Texture>(path);
tex->Load(_device);
_texCache[path] = tex;
}
sprite->SetTexture(tex);
_sprites.push_back(sprite);
return sprite;
}
The two goals of this method are
1. Create the Sprite using the texture cache.
2. Add the Sprite to the rendering list.
This is also where we have all of the code for the really simple texture cache that
we will be using. We use a simple std::map to store the textures, using the path as
the key; that way we know we'll get the same texture because it will have the same
path. Check for the texture and, if it doesn't exist, create it and load the texture from
disk before adding it into the cache and the sprite. Once we have a texture, from
the cache or disk, just add the sprite to our _sprites list that we use to easily loop
through and render every instance.
Now it's time to use this renderer in our game and finally see the results of our
structure and input system in action. Begin by calling Renderer::Initialise in-
side Game::LoadContent and Renderer::Draw inside Game::Render . This is
all we need to do to hook the rendering system up to the game. Now we just need
to create these sprites and we can try out our work. To do that, we need to fill in the
Ship::LoadTexture method and add in a std::shared_ptr to a Sprite ob-
ject to store the actual sprite.
void Ship::LoadTexture(std::wstring &path)
{
Search WWH ::




Custom Search