Hi All,
I am getting to grips with component based game objects (heavily using the example from game programming gems GPG 6), but run into implementation problems. I am using the DirectX toolkit for graphics rendering, and modifying the sample to prototype my design.
Right now, I am just trying to get one 'sprite' on screen, first I need to load the texture the sprite will use. Using the directX toolkit this is done by calling CreateDDSTextureFromFile(device, L"windowslogo.dds", nullptr, m_texture.ReleaseAndGetAddressOf()).
Where is the correct place to load the sprite sheet? Is it loaded inside a component? Or is the whole sprite sheet loaded at once (in say Game::init(), and components use the bits they need?
Then, when it comes to rendering, GPG 6 doesn't actually provide implementation details of virtual void render(); (inside the visual Component). DirectX TK draws with m_sprites->Draw(m_texture.Get(), XMFLOAT2(10, 75), nullptr, Colors::White); So again, I am a bit stuck. To draw like this, I need the std::unique_ptr<DirectX::SpriteBatch> m_sprites; Does this belong in a components private member?
This would mean my visual Component would look as follows:
class gocVisualCircle : public gocVisual
{
public:
virtual const goc_id_type& componentID() const {
return goc_id_type("gocVisualCircle");
}
virtual void render() const {
m_sprites->Draw(m_texture.Get(), XMFLOAT2(10, 75), nullptr, Colors::White);
};
gocVisualCircle(Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> m_texture) {
CreateDDSTextureFromFile(device, L"windowslogo.dds", nullptr, m_texture.ReleaseAndGetAddressOf());
};
private:
std::unique_ptr<DirectX::SpriteBatch> m_sprites;
};
Am I on the right track? I am worried that this is too closely coupled to the directX toolkit objects.
Thanks for your time and help.