Guest User

Example

a guest
May 16th, 2017
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 KB | None | 0 0
  1. //Main Draw in Game class
  2. protected override void Draw(GameTime gameTime)
  3. {
  4.     GraphicsDevice.Clear(Color.Black);
  5.  
  6.     switch(GameState)
  7.     {
  8.         case GameState.Menu: /*MenuDraw*/ break;
  9.         case GameState.Game: DrawGame(); break;
  10.         //etc
  11.     }
  12.  
  13.     base.Draw(gameTime);
  14. }
  15.  
  16. //DrawGame()
  17. private void DrawGame()
  18. {
  19.     spriteBatch.Begin(/*some parameters*/);
  20.  
  21.     for (int i = 0; i < GameObjects.Count; ++i)
  22.     {
  23.         //GameObjects is a List of game's objects
  24.         //GameObject is an abstract class, which other things inherit
  25.         //It has basic things, like Update and Draw functions
  26.  
  27.         GameObjects[i].Draw(spriteBatch);
  28.     }  
  29.  
  30.     spriteBatch.End();
  31. }
  32.  
  33. //Player inherits GameObject
  34. public class Player : GameObject
  35. {
  36.  
  37.     //Overriding Update from GameObject
  38.     public override void Update()
  39.     {
  40.         //Update Player
  41.     }
  42.  
  43.     //Overriding Update from GameObject
  44.     public override void Draw(SpriteBatch batch)
  45.     {
  46.         //Draw Player
  47.         //eg batch.Draw(Position, Texture, Color.White);
  48.     }
  49. }
Add Comment
Please, Sign In to add comment