raylibstarter 0.1.0
sprite.cpp
Go to the documentation of this file.
1#include <raylib.h>
2
3#include <utility>
4
5#include "sprite.h"
6
7game::core::Sprite::Sprite(std::shared_ptr<game::core::Texture2D> texture)
8 : Sprite(std::move(texture), 0, 0, 0.0f) {
9
10}
11
12game::core::Sprite::Sprite(std::shared_ptr<game::core::Texture2D> texture, int pos_x, int pos_y)
13 : Sprite(std::move(texture), pos_x, pos_y, 0.0f) {
14
15}
16
17game::core::Sprite::Sprite(std::shared_ptr<game::core::Texture2D> texture, int pos_x, int pos_y, float rotation)
18 : texture_(std::move(texture)),
19 frame_({0.0, 0.0,
20 static_cast<float>(this->texture_->width()),
21 static_cast<float>(this->texture_->height())}),
22 rotation_origin(
23 {static_cast<float>(this->texture_->width()) / 2,
24 static_cast<float>(this->texture_->height()) /2}),
25 rotation(rotation),
26 pos_x(pos_x),
27 pos_y(pos_y) {
28
29}
30
31game::core::Sprite::Sprite(std::shared_ptr<game::core::Texture2D> texture, int pos_x, int pos_y, Vector2 rotation_origin, float rotation, Rectangle frame)
32 : texture_(std::move(texture)),
33 frame_(frame),
34 rotation_origin(rotation_origin),
35 rotation(rotation),
36 pos_x(pos_x),
37 pos_y(pos_y) {
38
39}
40
42 TraceLog(LOG_INFO, "game::core::Sprite destructor called");
43}
44
46 return {static_cast<float>(this->pos_x), static_cast<float>(this->pos_y)};
47}
48
49[[maybe_unused]] const std::shared_ptr<game::core::Texture2D> &game::core::Sprite::texture_object() const {
50 return this->texture_;
51}
52
53void game::core::Sprite::texture(const std::shared_ptr<game::core::Texture2D> &texture) {
54 this->texture_ = texture;
55
56 this->frame_ = {0.0, 0.0,
57 static_cast<float>(this->texture_->width()),
58 static_cast<float>(this->texture_->height())};
59
60 this->rotation_origin = {static_cast<float>(this->texture_->width()) / 2,static_cast<float>(this->texture_->height()) /2};
61}
62
63const ::Texture2D &game::core::Sprite::texture() const {
64 return this->texture_->texture();
65}
66
67const Rectangle &game::core::Sprite::frame() const {
68 return this->frame_;
69}
70
71void game::core::Sprite::frame(const Rectangle &frame) {
72 this->frame_ = frame;
73}
The Sprite class specifies position and degree of rotation on the screen for an associated VRAM textu...
Definition: sprite.h:21
Vector2 position() const
Definition: sprite.cpp:45
std::shared_ptr< game::core::Texture2D > texture_
The sprites Texture2D.
Definition: sprite.h:24
const ::Texture2D & texture() const
Definition: sprite.cpp:63
virtual ~Sprite()
Definition: sprite.cpp:41
const std::shared_ptr< game::core::Texture2D > & texture_object() const
Definition: sprite.cpp:49
const Rectangle & frame() const
Definition: sprite.cpp:67
const ::Texture2D & texture() const
Definition: texture2d.cpp:15