Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class AnimationType {
- public float timerDefault = 100;
- public Sprite[] Assets { set; get; }
- public float[,] Frames { set; get; }
- public Vector2f _position;
- public Vector2f Position { set { _position = value; } get { return _position; } }
- public int _currentFrame = 0;
- public int CurrentFrame { set { _currentFrame = value; } get { return _currentFrame; } }
- public float _timer = 0;
- public float Timer { set { _timer = value; } get { return _timer; } }
- public bool _sorted = false;
- public bool Sorted { set { _sorted = value; } get { return _sorted; } }
- public AnimationType() {
- }
- public void SetPosition(Vector2f pos) {
- this.Position = pos;
- foreach (Sprite s in this.Assets) {
- s.Position = this.Position;
- }
- }
- public void Animate() {
- //set the sprite's position
- SetPosition(this.Position);
- //move the timer foreward.
- this.Timer += this.Frames[this.CurrentFrame, 2] * Globals.DeltaTime.AsSeconds();
- //if the timer moves past the limit, reset it and go to the next frame.
- if (this.Timer >= timerDefault) { this.Timer = 0; this.CurrentFrame += 1; }
- //if the frame counter goes past the limit, reset it. The animation is done.
- if (this.CurrentFrame > this.Frames.GetUpperBound(0)) { this.CurrentFrame = 0; }
- }
- public void Render(RenderWindow w) {
- w.Draw(this.Assets[this.CurrentFrame]);
- }
- }
- class Animation {
- public static AnimationType testAnimation = new AnimationType() {
- Position = new Vector2f(100,100),
- Assets = new Sprite[4] {
- new Sprite(new Texture(@"res\ts1.png")),
- new Sprite(new Texture(@"res\ts2.png")),
- new Sprite(new Texture(@"res\ts3.png")),
- new Sprite(new Texture(@"res\ts4.png")),
- },
- Frames = new float[4,3] {
- {0, 0, 200}, //order, sprite index, duration
- {1, 1, 200},
- {2, 2, 200},
- {3, 3, 200},
- },
- Sorted = true,
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement