-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsprite.cpp
executable file
·119 lines (101 loc) · 2.92 KB
/
sprite.cpp
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "headers/sprite.h"
Sprite::Sprite(int x, int y)
{
//mTexture = TextureLoader::Instance()->LoadTexture(path);
//SDL_QueryTexture(mTexture,NULL,NULL,&mWidth,&mHeight);
mX = x;
mY = y;
mXScaleFactor = mYScaleFactor = 1;
transformRect = {(int)mX, (int)mY, mWidth, mHeight};
mZIndex = Index_Background;
mXOffset = mYOffset = 0;
}
Sprite::Sprite(std::string path)
{
mTexture = TextureLoader::Instance()->LoadTexture(path);
SDL_QueryTexture(mTexture,NULL,NULL,&mWidth,&mHeight);
mX = mY = 0;
mXScaleFactor = mYScaleFactor = 1;
mXOffset = mYOffset = 0;
mZIndex = Index_Background;
}
Sprite::Sprite(std::string path,int x, int y)
{
mTexture = TextureLoader::Instance()->LoadTexture(path);
SDL_QueryTexture(mTexture,NULL,NULL,&mWidth,&mHeight);
mX = x;
mY = y;
mXScaleFactor = mYScaleFactor = 1;
transformRect = {(int)mX, (int)mY, mWidth, mHeight};
mXOffset = mYOffset = 0;
mZIndex = Index_Background;
}
Sprite::Sprite(std::string path,int x, int y, float scale)
{
mTexture = TextureLoader::Instance()->LoadTexture(path);
SDL_QueryTexture(mTexture,NULL,NULL,&mWidth,&mHeight);
mX = x;
mY = y;
mXOffset = mYOffset = 0;
mXScaleFactor = mYScaleFactor = scale;
transformRect = {(int)mX,(int)mY, (int)(mWidth * mXScaleFactor), (int)(mHeight * mYScaleFactor)};
mZIndex = Index_Background;
}
Sprite::Sprite(std::string path,int x, int y, float xScale, float yScale)
{
mTexture = TextureLoader::Instance()->LoadTexture(path);
SDL_QueryTexture(mTexture,NULL,NULL,&mWidth,&mHeight);
mX = x;
mY = y;
mXOffset = mYOffset = 0;
mXScaleFactor = xScale;
mYScaleFactor = yScale;
transformRect = {(int)mX, (int)mY, (int)(mWidth * mXScaleFactor), (int)(mHeight * mYScaleFactor)};
mZIndex = Index_Background;
}
SDL_Rect* Sprite::GetTransformRect()
{
transformRect = {(int)mX + mXOffset, (int)mY + mYOffset, (int)(mWidth * mXScaleFactor), (int)(mHeight * mYScaleFactor)};
return &transformRect;
}
void Sprite::SetTexture(std::string path)
{
mTexture = TextureLoader::Instance()->LoadTexture(path);
SDL_QueryTexture(mTexture,NULL,NULL,&mWidth,&mHeight);
transformRect = {(int)mX, (int)mY, (int)(mWidth * mXScaleFactor), (int)(mHeight * mYScaleFactor)};
}
void Sprite::SetPos(int x, int y)
{
mX = x;
mY = y;
//transformRect = {(int)mX, (int)mY, (int)(mWidth * mXScaleFactor), (int)(mHeight * mYScaleFactor)};
}
void Sprite::SetOffset(int _x, int _y)
{
mXOffset = _x;
mYOffset = _y;
//transformRect = {(int)mX + mXOffset, (int)mY + mYOffset, (int)(mWidth * mXScaleFactor), (int)(mHeight * mYScaleFactor)};
}
int Sprite::GetZIndex()
{
return mZIndex;
}
void Sprite::SetZIndex(int _newZIndex)
{
mZIndex = _newZIndex;
}
void Sprite::HandleEvents(SDL_Event e)
{
}
void Sprite::Update(double deltaTime)
{
}
Sprite::~Sprite()
{
SDL_DestroyTexture(mTexture);
mTexture = NULL;
}
SDL_Texture* Sprite::GetTexture()
{
return mTexture;
}