I'm currently making a shoot em up in monogame.
I've managed to make a constantly looping animation with my sprite but the problem is that I now don't know how to insert my animated sprite to myPlayer.
I don't want any commands only a constantly looped animation attached to myPlayer. I'm a beginner to programming so help is much appreciated.
This project is due soon so would love some help.
Game1:
Texture2D myPlayerAnim;
Rectangle myDestRect;
Rectangle mySourceRect;
Texture2D myEnemyAnim;
Rectangle myEnemyDestRect;
Rectangle myEnemySourceRect;
float myElapsed;
float myDelay = 100f;
int myFrames = 0;
Initialize:
myDestRect = new Rectangle(0, 0, 512, 512);
myEnemyDestRect = new Rectangle(0, 0, 808, 608);
LoadContent:
myPlayerAnim = Content.Load<Texture2D>("SpriteSheetPlayerAnim");
myEnemyAnim = Content.Load<Texture2D>("SpriteSheetEnemyAnim");
Update:
myElapsed += (float)aGameTime.ElapsedGameTime.TotalMilliseconds;
if (myElapsed >= myDelay)
{
if (myFrames >= 3)
{
myFrames = 0;
}
else
{
myFrames++;
}
myElapsed = 0;
}
mySourceRect = new Rectangle(512 * myFrames, 0, 512, 512);
myEnemySourceRect = new Rectangle(808 * myFrames, 0, 808, 608);
Draw:
mySpriteBatch.Draw(myPlayerAnim, myDestRect , mySourceRect,
Color.White);
mySpriteBatch.Draw(myEnemyAnim, myEnemyDestRect, myEnemySourceRect,
Color.White);
Draw currently only draws out the animation because it's not attached to anything.
currently myPlayer only has a single png attached and not my animation.
Draw:
myPlayer = new Player(TextureLibrary.GetTexture("player"), myPlayerPos, 200, new Vector2(.3f, .3f), 0, Color.White, 1000, 1);