NasNas
An intuitive and beginner friendly 2D game framework for C++
include
NasNas
core
graphics
Sprite.hpp
1
// Created by Modar Nasser on 20/04/2021.
2
3
#pragma once
4
5
#include <SFML/Graphics/Drawable.hpp>
6
#include <SFML/Graphics/RenderTarget.hpp>
7
#include <SFML/Graphics/Sprite.hpp>
8
#include <SFML/Graphics/Texture.hpp>
9
#include <SFML/Graphics/Vertex.hpp>
10
11
#include <NasNas/core/data/Rect.hpp>
12
#include <NasNas/core/graphics/Transformable.hpp>
13
14
namespace
ns
{
15
class
Sprite
:
public
sf::Drawable,
public
ns::Transformable
{
16
public
:
17
Sprite
() =
default
;
18
explicit
Sprite
(
const
sf::Sprite& other);
19
explicit
Sprite
(
const
sf::Texture& texture);
20
Sprite
(
const
sf::Texture& texture,
const
sf::IntRect& rectangle);
21
22
void
setTexture(
const
sf::Texture& texture,
bool
reset_rect =
false
);
23
void
setTextureRect(
const
sf::IntRect& rectangle);
24
25
void
setColor(
const
sf::Color& color);
26
void
setColor(
const
sf::Color& color,
unsigned
vert_index);
27
28
auto
getTexture()
const
->
const
sf::Texture*;
29
auto
getTextureRect()
const
->
const
IntRect
&;
30
31
auto
getColor()
const
->
const
sf::Color&;
32
auto
getColor(
unsigned
vert_index)
const
->
const
sf::Color&;
33
34
auto
getVertex(
unsigned
index)
const
->
const
sf::Vertex&;
35
36
auto
getLocalBounds()
const
->
ns::FloatRect
;
37
auto
getGlobalBounds()
const
->
ns::FloatRect
;
38
39
private
:
40
void
draw(sf::RenderTarget& target, sf::RenderStates states)
const override
;
41
42
sf::Vertex m_vertices[4];
43
const
sf::Texture* m_texture =
nullptr
;
44
ns::IntRect
m_texture_rect;
45
};
46
}
ns::Rect< int >
ns
ns::Sprite
Definition:
Sprite.hpp:15
ns::Transformable
Definition:
Transformable.hpp:8
Generated by
1.8.13