Game Development Reference
In-Depth Information
Sprite _spaceship ¼ new Sprite();
public PlayerCharacter(TextureManager textureManager)
{
_spaceship.Texture ¼ textureManager.Get("player_ship");
_spaceship.SetScale(0.5, 0.5); // spaceship is quite big, scale
it down.
}
public void Render(Renderer renderer)
{
renderer.DrawSprite(_spaceship);
}
}
The PlayerCharacter class at this stage only renders out the spaceship.
To see this is in action a Level object needs to be created in the
InnerGameState and hooked up to the Update and Render methods. The
structure of the level class has its own Render and Update methods so it's very
easy to plug into the InnerGame State . The Level class makes use of the
TextureManager class and this means the InnerGameState must change
its constructor so that it takes in a TextureManager object. In the form.cs file
the textureManager object needs to be passed into the InnerGameState
constructor.
class InnerGameState : IGameObject
{
Level _level;
TextureManager _textureManager;
// Code omitted
public InnerGameState( StateSystem system, Input input, TextureManager
textureManager,
PersistantGameData gameData, Font generalFont)
{
_ textureManager ¼ textureManager;
// Code omitted
public void OnGameStart()
{
_level ¼ new Level(_input, _textureManager, _gameData);
 
Search WWH ::




Custom Search