public void DrawSpriteBatch(SpriteBatch sb, string state, Game game, Vector2 offset, Direction dir = Direction.SOUTH, uint frame = 0, bool movement = false) { IconFrame f = GetIconState(state, movement).GetFrame(frame, dir); if (texture == null) { texture = Texture2D.FromStream(game.GraphicsDevice, new FileStream(FileName, FileMode.Open)); log.DebugFormat("Loaded Texture2D {0}", FileName); } sb.Draw(texture, offset, f.rect, Color.White); }
public SpriteBatch GetSpriteBatch(string state, Game game, Vector2 offset, Direction dir = Direction.SOUTH, uint frame = 0, bool movement = false) { IconFrame f = GetIconState(state, movement).GetFrame(frame, dir); using (SpriteBatch sb = new SpriteBatch(game.GraphicsDevice)) { //Console.WriteLine(f.rect.X + " " + f.rect.Y); //game.GraphicsDevice.Clear(Color.White); sb.Begin(); if (texture == null) { texture = Texture2D.FromStream(game.GraphicsDevice, new FileStream(FileName, FileMode.Open)); log.DebugFormat("Loaded Texture2D {0}", FileName); } sb.Draw(texture, offset, f.rect, Color.White); sb.End(); return(sb); } }
void loadFramesForState(ref int x, ref int y, ref int total, ref IconState currentState) { // Init array size. currentState.Initialize(); // Grab the icons we need, operating like a typewriter. // Loop X times, incrementing i from 0 to <X, where X = GetTotalNumIcons() for (int i = 0; i < currentState.GetTotalNumIcons(); i++) { // Make a new frame. IconFrame frame = new IconFrame(); // Icon # frame.frame = i; // Store our position and rectangle. frame.rect = new Rectangle(x * iconWidth, y * iconHeight, iconWidth, iconHeight); log.DebugFormat(" Frame {0}: {1}, {2}", i, x, y); // Store frame in the state. currentState.Frames[i] = frame; // Move over 1 icon X position. x++; // Bump total # of frames loaded. total++; // If we're over the number of columns, go to the next line. if (x >= columns) { x = 0; y++; log.DebugFormat("NEXT LINE: x={0}, y={1}", x, y); } } // Debug spam. log.DebugFormat("Loaded {0} icons for state {1}.", currentState.Frames.Length, currentState.Name); // Store state. states[currentState.GetCollKey()] = currentState; }
public void SetFrame(uint frame, Direction dir, IconFrame f) { Frames[GetFrameIndex(frame, dir)] = f; }