So I saw multiple tutorials using rectangle as an array. But their invaders are not animated. I'm using a spritesheet for my invaders and I need to have them all animated... How to do this?
Here's my invader class:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
namespace SpaceInvaders
{
class botInvaders
{
public botInvaders()
{
}
public static Texture2D BotInvaderTex;
Rectangle BotInvaderHitBox;
public static Vector2 BotInvaderPos = new Vector2(0, 28), BotInvaderOrigin;
int BotInvaderCurrentFrame = 1, BotInvaderFrameWidth = 52, BotInvaderFrameHeight = 88;
float Timer = 0f, Interval = 100f;
public void Initialize()
{
}
public void LoadContent(ContentManager Content)
{
BotInvaderTex = Content.Load<Texture2D>(".\\gameGraphics\\gameSprites\\botInvaders\\normalInvaders\\invaderShip1");
}
public void Update(GameTime gameTime)
{
BotInvaderHitBox = new Rectangle(BotInvaderCurrentFrame * BotInvaderFrameWidth, 0, BotInvaderFrameWidth, BotInvaderFrameHeight);
BotInvaderOrigin = new Vector2(BotInvaderHitBox.X / 2, BotInvaderHitBox.Y / 2);
Timer += (float)gameTime.ElapsedGameTime.Milliseconds;
if (Timer > Interval)
{
BotInvaderCurrentFrame++;
Timer = 0f;
}
if (BotInvaderCurrentFrame == 2)
{
BotInvaderCurrentFrame = 0;
}
BotInvaderHitBox = new Rectangle(BotInvaderCurrentFrame * BotInvaderFrameWidth, 0, BotInvaderFrameWidth, BotInvaderFrameHeight);
BotInvaderOrigin = new Vector2(BotInvaderHitBox.Width / 2, BotInvaderHitBox.Height / 2);
}
public void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(BotInvaderTex, BotInvaderPos, BotInvaderHitBox, Color.White, 0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0);
}
}
}
This shows how I animate the invaders. Can I have the portion of modified code so that there are 5 rows of invaders and 10 collumns? I can do the movement myself, I only need the array. Thanks in advance!