-
Notifications
You must be signed in to change notification settings - Fork 0
/
AnimatedSprite.h
64 lines (52 loc) · 2.05 KB
/
AnimatedSprite.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#pragma once
#include "Animation.h"
#include <SFML\Graphics.hpp>
#include "Includes.h"
//A Entity that holds arrays of animation to display an animated sprite using a sprite sheet
//Has basic entity stuff like position, size, velocity
//Designed to be extended by more specific entities like Player/Enemy
class AnimatedSprite
{
protected:
sf::Vector2f mPosition;
sf::Vector2f mVelocity;
//for rotation
float mAngle;
float mAngularVelocity;
//Sprite that hold and displays the texture
sf::Sprite mSprite;
//SpriteSize is used to determine size of the sprite on each spritesheet
//size should be scaled with the sprite for collision stuff/ actual ingame size
sf::Vector2i mSize;
sf::Vector2i mSpriteSize;
//store which array of animation is currently being used
int mCurrentAnimation;
bool mIsAnimating;
//array of class Animation to store all the different Animations like Idle/Walk/Jump
std::vector<Animation> mAnimations;
public:
AnimatedSprite(
sf::Vector2f pPosition,
sf::Vector2f pVelocity,
sf::Vector2i pSize,
sf::Texture *pTexture,
float pAngle = 0,
float pAngularVelocity = 0);
virtual ~AnimatedSprite(void);
virtual void startAnimation();
virtual void endAnimation();
virtual void update();
virtual void draw(sf::RenderWindow *window, float pInterpolation);
//getters and setters
//change what the current animation is like idle/jump/walk
virtual void setCurrentAnimation(int pRow) { mCurrentAnimation = pRow; }
//get bounds in global space for use in collision detection
virtual sf::FloatRect getBounds() { return mSprite.getGlobalBounds(); }
virtual sf::Vector2f getPosition() { return mPosition; }
virtual sf::Vector2i getSize() { return mSize; }
virtual sf::Vector2f getVelocity() { return mVelocity; }
virtual void setVelocity(float pX, float pY) { mVelocity = sf::Vector2f(pX,pY); };
virtual void setVelocity(sf::Vector2f pVelocity) { mVelocity = pVelocity; };
virtual void setPosition(float pX, float pY) { mPosition = sf::Vector2f(pX,pY); };
virtual void setPosition(sf::Vector2f pPosition) { mPosition = pPosition; };
};