Hi,
I want to do a simple explosion on a collision.Here is my code..
public explosion(Texture2D newTexture, Vector2 newPosition)
{
texture = newTexture;
position = newPosition;
timer = 0f;
interval = 40f;
currentFrame = 1;
spriteWidth = 60;
spritHeight = 60;
isVisible = true;
}
public void Update(GameTime gameTime)
{
timer += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
if (timer > interval)
{
currentFrame++;
timer = 0f;
}
if (currentFrame == 32)
{
isVisible = false;
currentFrame = 0;
}
sourceRect = new Rectangle(currentFrame * spriteWidth, 0, spriteWidth, spritHeight);
origin = new Vector2(sourceRect.Width/2, sourceRect.Height / 2);
}
public void Draw(SpriteBatch spriteBatch)
{
if (isVisible == true)
{
spriteBatch.Draw(texture, position, sourceRect, Color.White, 0f, origin,1.0f, SpriteEffects.None,0);
}
}
during collision I am loading like this--
foreach (Enemy e in this.em.Enemies)
{
if (i.BoundingRectangle.Intersects(e.BoundingRectangle))
{
explList.Add(new explosion(cm.Load<Texture2D>("Exp"), new Vector2(e.position.X, e.position.Y)));
e.OnHit();
}
}
problem is instead of appearing one by one frames,frames are moving to the right side one by one in the rectangle.I am totally new to XNA .Pls help...........
dj_Fox
No comments:
Post a Comment