-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSprite.cpp
More file actions
32 lines (24 loc) · 826 Bytes
/
Copy pathSprite.cpp
File metadata and controls
32 lines (24 loc) · 826 Bytes
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
#include "Sprite.h"
#include "Graphics.h"
#include "Globals.h"
Sprite::Sprite() {}
Sprite::Sprite(Graphics& graphics, const std::string& filePath, int sourceX, int sourceY, int width, int height,
float posX, float posY) :
_x(posX),
_y(posY)
{
_sourceRect.x = sourceX;
_sourceRect.y = sourceY;
_sourceRect.w = width;
_sourceRect.h = height;
_spriteSheet = SDL_CreateTextureFromSurface(graphics.getRenderer(), graphics.loadImage(filePath));
if (_spriteSheet == NULL) {
printf("\n Error: Unable to load image\n");
}
}
Sprite::~Sprite() {}
void Sprite::draw(Graphics& graphics, int x, int y) {
SDL_Rect destinationRectangle = { x, y, _sourceRect.w * globals::SPRITE_SC, _sourceRect.h * globals::SPRITE_SC };
graphics.blitSurface(_spriteSheet, &_sourceRect, &destinationRectangle);
}
void Sprite::update() {}