Gamedev Framework (gf) 1.2.0
A C++17 framework for 2D games
BasicSprite.h
1/*
2 * Gamedev Framework (gf)
3 * Copyright (C) 2016-2022 Julien Bernard
4 *
5 * This software is provided 'as-is', without any express or implied
6 * warranty. In no event will the authors be held liable for any damages
7 * arising from the use of this software.
8 *
9 * Permission is granted to anyone to use this software for any purpose,
10 * including commercial applications, and to alter it and redistribute it
11 * freely, subject to the following restrictions:
12 *
13 * 1. The origin of this software must not be misrepresented; you must not
14 * claim that you wrote the original software. If you use this software
15 * in a product, an acknowledgment in the product documentation would be
16 * appreciated but is not required.
17 * 2. Altered source versions must be plainly marked as such, and must not be
18 * misrepresented as being the original software.
19 * 3. This notice may not be removed or altered from any source distribution.
20 *
21 * Part of this file comes from SFML, with the same license:
22 * Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
23 */
24#ifndef GF_BASIC_SPRITE_H
25#define GF_BASIC_SPRITE_H
26
27#include "GraphicsApi.h"
28#include "Rect.h"
29#include "Span.h"
30
31namespace gf {
32#ifndef DOXYGEN_SHOULD_SKIP_THIS
33inline namespace v1 {
34#endif
35 class Texture;
36 struct Vertex;
37
46 class GF_GRAPHICS_API BasicSprite {
47 public:
54
62 BasicSprite(const Texture& texture);
63
72 BasicSprite(const Texture& texture, const RectF& textureRect);
73
92 [[deprecated("You should use setTexture(const Texture&, const RectF&) instead")]]
93 void setTexture(const Texture& texture, bool resetRect);
94
111 void setTexture(const Texture& texture, const RectF& textureRect = RectF::fromSize({ 1.0f, 1.0f }));
112
123 const Texture& getTexture() const {
124 return *m_texture;
125 }
126
134 bool hasTexture() const {
135 return m_texture != nullptr;
136 }
137
146
162 void setTextureRect(const RectF& rect);
163
171 const RectF& getTextureRect() const {
172 return m_textureRect;
173 }
174
187
188
190
191 private:
192 const Texture *m_texture;
193 RectF m_textureRect;
194 RectF m_bounds;
195 };
196
197#ifndef DOXYGEN_SHOULD_SKIP_THIS
198}
199#endif
200}
201
202#endif // GF_BASIC_SPRITE_H
A basic sprite.
Definition: BasicSprite.h:46
RectF getLocalBounds() const
Get the local bounding rectangle of the entity.
void updateGeometry(Span< Vertex > vertices)
void setTexture(const Texture &texture, const RectF &textureRect=RectF::fromSize({ 1.0f, 1.0f }))
Change the source texture of the sprite.
void setTextureRect(const RectF &rect)
Set the sub-rectangle of the texture that the sprite will display.
const RectF & getTextureRect() const
Get the sub-rectangle of the texture displayed by the sprite.
Definition: BasicSprite.h:171
void unsetTexture()
Unset the source texture of the sprite.
const Texture & getTexture() const
Get the source texture of the sprite.
Definition: BasicSprite.h:123
void setTexture(const Texture &texture, bool resetRect)
Change the source texture of the sprite.
BasicSprite()
Default constructor.
BasicSprite(const Texture &texture)
Construct the sprite from a source texture.
bool hasTexture() const
Check if a texture is set.
Definition: BasicSprite.h:134
BasicSprite(const Texture &texture, const RectF &textureRect)
Construct the sprite from a sub-rectangle of a source texture.
A span.
Definition: Span.h:414
A texture for colored images.
Definition: Texture.h:313
@ Texture
A GPU texture.
The namespace for gf classes.
static constexpr Rect< float > fromSize(Vector< float, 2 > size) noexcept
Create a rectangle from a size.
Definition: Rect.h:114