Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In this commit I added particle system from Microsoft XNA samples (converted to SFML ofc). Also, I removed SpriteBatch (unoptimized one) and made VertexBatch as default.
- Loading branch information
Showing
24 changed files
with
1,237 additions
and
968 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using SFML.Graphics; | ||
using SFGL.Time; | ||
|
||
namespace SFGL.Graphics | ||
{ | ||
public class AnimatedSprite : Sprite, IUpdateable | ||
{ | ||
private int activeFrame; | ||
private List<Rectangle> frames; | ||
private Rectangle currentFrame; | ||
private GameTime elapsedTime; | ||
private float frameDelay; | ||
|
||
// how long it has been since initialize was called | ||
private float timeSinceStart; | ||
|
||
/// <summary> | ||
/// List with the frames of the animation | ||
/// </summary> | ||
public List<Rectangle> Frames | ||
{ | ||
get { return frames; } | ||
set { frames = value; } | ||
} | ||
|
||
/// <summary> | ||
/// Defines for how long will be one frame drawn | ||
/// </summary> | ||
public float FrameDelay | ||
{ | ||
get { return frameDelay; } | ||
set { frameDelay = value; } | ||
} | ||
|
||
public AnimatedSprite (Texture texture, IntRect rectangle) : base (texture, rectangle) | ||
{ | ||
} | ||
|
||
public AnimatedSprite (Sprite copy) : base (copy) | ||
{ | ||
} | ||
|
||
public AnimatedSprite () : base () | ||
{ | ||
} | ||
|
||
public AnimatedSprite (Texture texture) : base (texture) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Allows the game component to update itself. | ||
/// </summary> | ||
/// <param name="gameTime">Provides a snapshot of timing values.</param> | ||
public void Update(GameTime gameTime) | ||
{ | ||
// calculate dt, the change in the since the last frame. the particle | ||
// updates will use this value. | ||
float dt = (float)gameTime.ElapsedGameTime.TotalMilliseconds; | ||
|
||
timeSinceStart += dt; | ||
|
||
// it's time to a next frame? | ||
if (timeSinceStart > frameDelay) | ||
{ | ||
timeSinceStart -= frameDelay; | ||
activeFrame++; | ||
if (activeFrame == frames.Count) | ||
{ | ||
activeFrame = 0; | ||
} | ||
// Get the current frame | ||
currentFrame = frames[activeFrame]; | ||
base.TextureRect = new IntRect ( | ||
currentFrame.X, | ||
currentFrame.Y, | ||
currentFrame.Width, | ||
currentFrame.Height); | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.