Game Development Reference
In-Depth Information
swaps that need to occur, which can often be a major bottleneck for texture heavy
games.
Finishing the batch
Now that we have begun rendering, we can draw each texture individually. To do
this, we'll add a Draw method to our Texture class that will handle the rendering
for you. Inside the Texture class header, declare the following method prototype
under the internal modifier:
void Draw(std::shared_ptr<DirectX::SpriteBatch>
batch);
Once you've done that, implement the method in the .cpp file by adding the follow-
ing code:
void
Texture::Draw(std::shared_ptr<DirectX::SpriteBatch>
batch)
{
auto vPos = DirectX::XMLoadFloat2(&_pos);
batch->Draw(_srv.Get(), vPos, nullptr);
}
The main part of this method is the call to batch->Draw() , which tells the
SpriteBatch to draw the texture, or save it for later (depending on which sort mode
you chose).
We need to tell the Draw call where to place the sprite on the screen. This is done
through the second parameter, which asks for an FXMVECTOR from the Direc-
tXMath library that comes with Direct3D and Windows 8. To do this we will have
to load our _ pos variable, which is stored as XMFLOAT2 (X, Y) , into XMVECTOR ,
which can be passed to the Draw function.
After that, we will pass a nullptr value to the final parameter, which asks us to
define which region of the texture should be drawn. Here we can define a sub-re-
Search WWH ::




Custom Search