GameContent Class Sample

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Media; namespace BrainBouncer { public class GameContent { //Music and sounds public Song bgMusic; //Backgrounds public Texture2D bg0 { get; set; } public Texture2D bg1 { get; set;} public Texture2D bg2 { get; set; } //Background map public Dictionary<string, Texture2D> bgMap { get; } //Sprites public Texture2D imgWall{get;set;} public Texture2D imgBall{get;set;} public Texture2D imgSquare{get;set;} public Texture2D imgPlayButtonBase { get; set; } public Texture2D imgPlayButtonHover { get; set; } public Texture2D imgPlayButtonPress { get; set; } //Fonts public SpriteFont UIFont { get; set; } public GameContent(ContentManager Content) { //load sounds bgMusic = Content.Load<Song>("snd_snowy_song"); //load backgrounds bg0 = Content.Load<Texture2D>("background0"); bg1 = Content.Load<Texture2D>("background1"); bg2 = Content.Load<Texture2D>("background2"); bgMap = new Dictionary<string, Texture2D>(); CreateBgMap(); //load sprites imgWall = Content.Load<Texture2D>("spr_block_0"); imgBall = Content.Load<Texture2D>("spr_ball_0"); imgSquare = Content.Load<Texture2D>("spr_square_0"); //button images imgPlayButtonBase = Content.Load<Texture2D>("spr_play_button_0"); imgPlayButtonHover = Content.Load<Texture2D>("spr_play_button_1"); imgPlayButtonPress = Content.Load<Texture2D>("spr_play_button_2"); //load fonts UIFont = Content.Load<SpriteFont>("UIFont"); } private void CreateBgMap() { bgMap.Add("background0", bg0); bgMap.Add("background1", bg1); bgMap.Add("background2", bg2); } } }
Class for loading content in my MonoGame puzzle game.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.