-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSprite.cpp
89 lines (67 loc) · 1.35 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
#include "Sprite.h"
Sprite::Sprite()
{
clips = NULL;
noOfSprites = 0;
offsetX = 0;
offsetY = 0;
texture.Free();
}
Sprite::~Sprite()
{
texture.Free();
clips = NULL;
}
void Sprite::LoadSpriteTexture(SDL_Renderer* renderer, const char* path, int spriteCount)
{
if (!texture.LoadFromFile(renderer, path))
{
printf("Failed to load texture : %s into sprite", path);
}
else
{
if (spriteCount > 1)
{
clips = new SDL_Rect[spriteCount];
noOfSprites = spriteCount;
}
else
{
noOfSprites = 1;
}
}
}
void Sprite::SetClip(int index, SDL_Rect* rect)
{
clips[index] = *rect;
}
SDL_Rect* Sprite::GetClip(int index)
{
return &clips[index];
}
int Sprite::GetClipCount()
{
return noOfSprites;
}
void Sprite::Render(int x, int y, SDL_Rect* clip, double* angle, SDL_Point* center, SDL_RendererFlip flip, double* scale)
{
texture.SetScale(*scale);
texture.Render(x, y, clip, angle, center, flip);
}
void Sprite::Start()
{
}
void Sprite::Update()
{
//printf("\nTransform position : %d, %d \n", transform->position.x, transform->position.y);
//transform->position.x -= offsetX;
//transform->position.y -= offsetY;
Render(transform->position.x, transform->position.y, NULL, &transform->rotation, NULL, SDL_FLIP_NONE, &transform->scale);
}
void Sprite::Destroy()
{
}
void Sprite::SetTextureScale(double value)
{
texture.SetScale(value);
}