Added texture cache and sprite origins.

This commit is contained in:
2026-01-14 23:09:13 -05:00
parent fcb4f1cf05
commit 61d51f5188
36 changed files with 319 additions and 83 deletions

View File

@@ -3,17 +3,25 @@ using Microsoft.Xna.Framework.Graphics;
namespace AlienAttack.MonoGame.Things;
public class Explosion(int x, int y, float xVel, float yVel) : Sprite(x, y)
public class Explosion : MoveableSprite
{
protected int CurrentFrame { get; private set; } = 1;
protected int MaxFrames => 9;
protected int AnimationThreshold => 3; //5;
protected int CurrentThreshold { get; private set; } = 5;
public Explosion(int x, int y, float xVel, float yVel) : base(x, y)
{
Origin = new(32.5f, 32);
XVelocity = xVel;
YVelocity = yVel;
}
public override void Draw(SpriteDrawArgs args)
{
Texture2D texture = args.Content.Load<Texture2D>(@$"Sprites\Explosion01_Frame_0{CurrentFrame}_png_processed");
args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, new Vector2(0, 0), 1f, SpriteEffects.None, 1);
//args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, new Vector2(0, 0), 1f, SpriteEffects.None, 1);
args.SpriteBatch.Draw(texture, Position, null, DrawColor, 0, Origin, 1f, SpriteEffects.None, 1);
base.Draw(args);
}
@@ -22,8 +30,8 @@ public class Explosion(int x, int y, float xVel, float yVel) : Sprite(x, y)
{
base.Update(context);
XPosition += xVel;
YPosition += yVel;
//XPosition += XVelocity;
//YPosition += YVelocity;
if (CurrentThreshold > 0)
{