Gamedev Framework (gf)
0.7.0
A C++14 framework for 2D games
include
gf
Sprite.h
1
/*
2
* Gamedev Framework (gf)
3
* Copyright (C) 2016-2018 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_SPRITE_H
25
#define GF_SPRITE_H
26
27
#include "Transformable.h"
28
#include "Portability.h"
29
#include "Vertex.h"
30
#include "VertexBuffer.h"
31
32
namespace
gf
{
33
#ifndef DOXYGEN_SHOULD_SKIP_THIS
34
inline
namespace
v1 {
35
#endif
36
class
Texture;
37
87
class
GF_API
Sprite
:
public
Transformable
{
88
public
:
94
Sprite
();
95
103
Sprite
(
const
Texture
& texture);
104
113
Sprite
(
const
Texture
& texture,
const
RectF
& textureRect);
114
133
void
setTexture(
const
Texture
& texture,
bool
resetRect =
false
);
134
145
const
Texture
&
getTexture
()
const
{
146
return
*m_texture;
147
}
148
156
bool
hasTexture
()
const
{
157
return
m_texture !=
nullptr
;
158
}
159
167
void
unsetTexture();
168
184
void
setTextureRect(
const
RectF
& rect);
185
193
const
RectF
&
getTextureRect
()
const
{
194
return
m_textureRect;
195
}
196
210
void
setColor(
const
Color4f
& color);
211
219
const
Color4f
& getColor()
const
;
220
221
233
RectF
getLocalBounds()
const
;
234
245
void
setAnchor(
Anchor
anchor);
246
255
VertexBuffer
commitGeometry()
const
;
256
257
virtual
void
draw(
RenderTarget
& target,
RenderStates
states)
override
;
258
259
private
:
260
void
updatePositions();
261
void
updateTexCoords();
262
263
private
:
264
const
Texture
*m_texture;
265
RectF
m_textureRect;
266
Vertex
m_vertices[4];
267
RectF
m_bounds;
268
};
269
270
#ifndef DOXYGEN_SHOULD_SKIP_THIS
271
}
272
#endif
273
}
274
275
#endif // GF_SPRITE_H
gf::Transformable
Decomposed transform defined by a position, a rotation and a scale.
Definition:
Transformable.h:95
gf::RenderTarget
Base class for all render targets (window, texture, ...)
Definition:
RenderTarget.h:66
gf::RenderStates
Define the states used for drawing to a RenderTarget.
Definition:
RenderStates.h:82
gf::Vertex
A point associated with a color and a texture coordinate.
Definition:
Vertex.h:75
gf::Sprite
A drawable representation of a texture, with its own transformations, color, etc. ...
Definition:
Sprite.h:87
gf::VertexBuffer
Data in the graphics memory.
Definition:
VertexBuffer.h:70
gf::Texture
A texture for colored images.
Definition:
Texture.h:339
gf::Rect< float >
gf
The namespace for gf classes.
Definition:
Action.h:34
gf::Anchor
Anchor
An anchor of a box.
Definition:
Anchor.h:38
gf::Sprite::hasTexture
bool hasTexture() const
Check if a texture is set.
Definition:
Sprite.h:156
gf::Vector< float, 4 >
gf::Sprite::getTextureRect
const RectF & getTextureRect() const
Get the sub-rectangle of the texture displayed by the sprite.
Definition:
Sprite.h:193
gf::Sprite::getTexture
const Texture & getTexture() const
Get the source texture of the sprite.
Definition:
Sprite.h:145
Generated by
1.8.13