Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Written 2017 by Michał Przekota.
- To the extent possible under law, the author(s) have dedicated all copyright to men who want to help with the problem.
- */
- #pragma once
- #include "Animation.h"
- class SpriteSheetAnimation : public Animation
- {
- public:
- SpriteSheetAnimation();
- ~SpriteSheetAnimation();
- void Draw(Animation &a,SDL_Renderer *renderer);
- void Update(Animation &a);
- private:
- Uint32 ticks, sprite;
- int frameCounter, switchFrame;
- };
- /*Written 2017 by Michał Przekota.
- To the extent possible under law, the author(s) have dedicated all copyright to men who want to help with the problem.
- */
- #ifndef DEBUG
- #define DEBUG
- #include "SpriteSheetAnimation.h"
- SpriteSheetAnimation::SpriteSheetAnimation()
- {
- frameCounter = 0;
- switchFrame = 100;
- }
- SpriteSheetAnimation::~SpriteSheetAnimation()
- {
- }
- void SpriteSheetAnimation::Draw(Animation &a, SDL_Renderer *renderer)
- {
- }
- void SpriteSheetAnimation::Update(Animation &a)
- {
- if (a.getActive())
- {
- frameCounter++;
- ticks = SDL_GetTicks();
- sprite = (ticks*6/1000) % 4;
- if (frameCounter >= switchFrame)
- {
- frameCounter = 0;
- a.CurrentFrame().first++;
- if (a.CurrentFrame().first * a.FrameDimentions().first >= a.Image().getWidth())
- {
- a.CurrentFrame().first = 0;
- }
- }
- }
- else
- {
- frameCounter = 0;
- a.CurrentFrame().first = 1;
- sprite = 1;
- }
- a.GetSourceRect().x = a.FrameDimentions().first * sprite;
- a.GetSourceRect().y = a.CurrentFrame().second *a.FrameDimentions().second;
- a.GetSourceRect().w = a.FrameDimentions().first;
- a.GetSourceRect().h = a.FrameDimentions().second;
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement