-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrawable.cpp
More file actions
44 lines (37 loc) · 769 Bytes
/
drawable.cpp
File metadata and controls
44 lines (37 loc) · 769 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
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <utility>
#include <cstdlib>
#include "drawable.h"
#include "render.h"
using namespace std;
Drawable::Drawable(Drawable&& other)
: _texture(exchange(other._texture, nullptr))
, _surface(exchange(other._surface, nullptr))
{}
Drawable::~Drawable()
{
SDL_FreeSurface(_surface);
SDL_DestroyTexture(_texture);
}
void Drawable::update()
{
if (!_uflag)
return;
_uflag = false;
if (!_surface) {
cerr << "Invalid surface" << endl;
exit(1);
}
// Destroy old texture
if (_texture)
SDL_DestroyTexture(_texture);
// Create texture from surface
_texture = SDL_CreateTextureFromSurface(
RenderWindow::get_instance().get_renderer(),
_surface
);
if (!_texture) {
cerr << "Failed to create texture" << endl;
exit(1);
}
}