Game Development Reference
In-Depth Information
_vertexUVs[3]= new Point(bottomRight.X, topLeft.Y);
_vertexUVs[4]= bottomRight;
_vertexUVs[5]= new Point(topLeft.X, bottomRight.Y);
}
}
The sprite class is quite large, mainly due to accessor functions and some
overloaded functions. The sprite has a default constructor; it creates a sprite of
size 1 by 1 with an empty texture. Once a texture is set, the width and height of
the sprite is automatically set to the texture values. Once the sprite is created, the
position, dimension, textures, and U,Vs can all be changed as needed.
Using the Sprite Class
With sprite code packaged into a class, it's now time to demonstrate how to use
it. Create a new game state called TestSpriteClassState , load it into the
state system, and make it the default state to run when the program executes.
TestSpriteClassState will need to take the TextureManager in to its
constructor like the DrawSpriteState did.
Renderer _renderer = new Renderer();
TextureManager _textureManager;
Sprite _testSprite = new Sprite();
Sprite _testSprite2 = new Sprite();
public TestSpriteClassState(TextureManager textureManager)
{
_textureManager = textureManager;
_testSprite.Texture = _textureManager.Get("face_alpha");
_testSprite.SetHeight(256*0.5f);
_testSprite2.Texture = _textureManager.Get("face_alpha");
_testSprite2.SetPosition(-256, -256);
_testSprite2.SetColor(new Color(1, 0, 0, 1));
}
public void Render()
{
Gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
_renderer.DrawSprite(_testSprite);
 
Search WWH ::




Custom Search