/// <summary> /// Draws the sprite /// </summary> /// <param name="rand">An instance of the class Random</param> /// <param name="spriteBatch">The currently used SpriteBatch</param> /// <param name="camera">The active camera</param> /// <param name="position">The position of the Sprite</param> /// <param name="scale">The scale the texture will be drawn with (this doesn't exclude the base-scale)</param> /// <param name="angle">The angle with which the texture is to be drawn</param> /// <param name="origin">The origin of the rotation</param> /// <param name="color">The color of the sprite</param> public void Draw(SpriteBatch spriteBatch, Camera camera, Vector2 position, Vector2 scale, float angle, Vector2 origin, Color color, float opacity, Animation animation, SpriteEffects spriteEffect, float depth) { if (currentTexture == textures.Count - 1 && ((int)Math.Floor(currentFrame) == frames[(int)Math.Floor(currentTexture)] || !spriteSheet[(int)Math.Floor(currentTexture)])) { animationEnd = true; } else { animationEnd = false; } if (draw && (camera.rectangle.Intersects(new Rectangle(Game1.CeilAdv(position.X), Game1.CeilAdv(position.Y), width, height)) || HUD)) { if (!animated) { spriteBatch.Draw(textures[0], position, null, GetColorOpaque(color, opacity), angle, origin, scale * this.scale, spriteEffect, depth); } else { if (spriteSheet[(int)Math.Floor(animation.currentTexture)]) { int x = (int)(animation.currentFrame % Math.Floor((float)(textures[(int)Math.Floor(animation.currentTexture)].Width / width))) * width; int y = (int)Math.Floor(animation.currentFrame / (textures[(int)Math.Floor(animation.currentTexture)].Width / width)) * height; spriteBatch.Draw(textures[(int)Math.Floor(animation.currentTexture)], position, new Rectangle(x, y, width, height), GetColorOpaque(color, opacity), angle, origin, scale * this.scale, spriteEffect, depth); } else { spriteBatch.Draw(textures[(int)Math.Floor(animation.currentTexture)], position, null, GetColorOpaque(color, opacity), angle, origin, scale * this.scale, spriteEffect, depth); } } } if (animated) { if (spriteSheet[(int)Math.Floor(animation.currentTexture)]) { if (animation.currentFrame >= frames[(int)Math.Floor(animation.currentTexture)]) { animation.currentFrame = 0; animation.currentTexture = (animation.currentTexture + 1) % (textures.Count); } else { animation.currentFrame = (animation.currentFrame + animation.speed); } } else { animation.currentTexture = (animation.currentTexture + animation.speed) % (textures.Count); } } if (drawOnce && animationEnd) { draw = false; } }
/// <summary> /// Draws the sprite /// </summary> /// <param name="rand">An instance of the class Random</param> /// <param name="spriteBatch">The currently used SpriteBatch</param> /// <param name="camera">The active camera</param> /// <param name="position">The position of the Sprite</param> public void Draw(SpriteBatch spriteBatch, Camera camera, Rectangle rectangle, Rectangle sourceRectangle, SpriteEffects spriteEffect, float depth) { if (currentTexture == textures.Count - 1 && ((int)Math.Floor(currentFrame) == frames[(int)Math.Floor(currentTexture)] || !spriteSheet[(int)Math.Floor(currentTexture)])) { animationEnd = true; } else { animationEnd = false; } if (draw && (camera.rectangle.Intersects(new Rectangle(Game1.CeilAdv(rectangle.X), Game1.CeilAdv(rectangle.Y), width, height)) || HUD)) { if (!animated) { spriteBatch.Draw(textures[0], rectangle.Location.ToVector2(), sourceRectangle, GetColorOpaque(color, opacity), angle, origin, scale, spriteEffect, depth); } else { if (spriteSheet[(int)Math.Floor(currentTexture)]) { int x = (int)(currentFrame % Math.Floor((float)(textures[(int)Math.Floor(currentTexture)].Width / width))) * width; int y = (int)Math.Floor(currentFrame / (textures[(int)Math.Floor(currentTexture)].Width / width)) * height; spriteBatch.Draw(textures[(int)Math.Floor(currentTexture)], rectangle.Location.ToVector2(), new Rectangle(x + sourceRectangle.X, y + sourceRectangle.Y, sourceRectangle.Width, sourceRectangle.Height), GetColorOpaque(color, opacity), angle, origin, scale, spriteEffect, depth); } else { spriteBatch.Draw(textures[(int)Math.Floor(currentTexture)], rectangle.Location.ToVector2(), null, GetColorOpaque(color, opacity), angle, origin, scale, spriteEffect, depth); } } } if (animated) { if (spriteSheet[(int)Math.Floor(currentTexture)]) { if (currentFrame >= frames[(int)Math.Floor(currentTexture)]) { currentFrame = 0; currentTexture = (currentTexture + 1) % (textures.Count); } else { currentFrame = (currentFrame + speed); } } else { currentTexture = (currentTexture + speed) % (textures.Count); } } if (drawOnce && animationEnd) { draw = false; } }