I keep running into errors when I try to draw an Array onto the screen using a specific section of my Sprite-sheet.
Here's the code I have to actually create my sprite-sheet:
#fields
// Fireball variables
private Point frameSize6 = new Point(48, 47); // Fireball image size
private Point currentFrame6 = new Point(0, 0); // Start frame
private Point sheetSize6 = new Point(1, 6); // Spritesheet size
private int noOfFireballs = 15; // Total number of fireballs to display
Vector2[] fireballPos; // Position of fireball(s)
private int timeSinceLastFrame = 0;
private int milliSecondsPerFrame = 500; // 2 Frames Per Second (fps)
#initialisation
// Setup Fireballs
fireballPos = new Vector2[noOfFireballs]; // Position of fireballs
private void resetGame()
{
for (int i = 0; i < noOfFireballs; i++) // Keep looping until each Fireball has been given a position
{
fireballPos[i].X = Math.Max(0, rand.Next(gameWidth) - frameSize6.X);
fireballPos[i].Y = Math.Max(-500, rand.Next(gameHeight) - frameSize6.Y);
}
}
public override void LoadContent()
{
spriteBatch = ScreenManager.SpriteBatch;
fireballs = content.Load<Texture2D>("Graphics/Sprites/fireballs");
}
#update and draw
...
I can draw the entire sprite-sheet onto the screen by using:
for (int i = 0; i < noOfFireballs; i++)
{
spriteBatch.Draw(fireballs, fireballPos[i], Color.White);
}
but it doesn't seem to use the current frame I specified.. :S
How would I go about doing this?
Thank you