SFML 2.5.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

Sprite.hpp
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages 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 freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25#ifndef SFML_SPRITE_HPP
26#define SFML_SPRITE_HPP
27
29// Headers
31#include <SFML/Graphics/Export.hpp>
32#include <SFML/Graphics/Drawable.hpp>
33#include <SFML/Graphics/Transformable.hpp>
34#include <SFML/Graphics/Vertex.hpp>
35#include <SFML/Graphics/Rect.hpp>
36
37
38 namespace sf
39{
40 class Texture;
41
47 class SFML_GRAPHICS_API Sprite : public Drawable, public Transformable
48{
49 public:
50
57 Sprite();
58
67 explicit Sprite(const Texture& texture);
68
78 Sprite(const Texture& texture, const IntRect& rectangle);
79
99 void setTexture(const Texture& texture, bool resetRect = false);
100
113 void setTextureRect(const IntRect& rectangle);
114
128 void setColor(const Color& color);
129
142 const Texture* getTexture() const;
143
152 const IntRect& getTextureRect() const;
153
162 const Color& getColor() const;
163
176 FloatRect getLocalBounds() const;
177
190 FloatRect getGlobalBounds() const;
191
192 private:
193
201 virtual void draw(RenderTarget& target, RenderStates states) const;
202
207 void updatePositions();
208
213 void updateTexCoords();
214
216 // Member data
218 Vertex m_vertices[4];
219 const Texture* m_texture;
220 IntRect m_textureRect;
221};
222
223} // namespace sf
224
225
226#endif // SFML_SPRITE_HPP
227
228
sf::Color
Utility class for manipulating RGBA colors.
Definition: Color.hpp:41
sf::Drawable
Abstract base class for objects that can be drawn to a render target.
Definition: Drawable.hpp:45
sf::Rect< int >
sf::RenderStates
Define the states used for drawing to a RenderTarget.
Definition: RenderStates.hpp:46
sf::RenderTarget
Base class for all render targets (window, texture, ...)
Definition: RenderTarget.hpp:53
sf::Sprite
Drawable representation of a texture, with its own transformations, color, etc.
Definition: Sprite.hpp:48
sf::Sprite::Sprite
Sprite(const Texture &texture, const IntRect &rectangle)
Construct the sprite from a sub-rectangle of a source texture.
sf::Sprite::setColor
void setColor(const Color &color)
Set the global color of the sprite.
sf::Sprite::Sprite
Sprite(const Texture &texture)
Construct the sprite from a source texture.
sf::Sprite::setTexture
void setTexture(const Texture &texture, bool resetRect=false)
Change the source texture of the sprite.
sf::Sprite::setTextureRect
void setTextureRect(const IntRect &rectangle)
Set the sub-rectangle of the texture that the sprite will display.
sf::Sprite::getTexture
const Texture * getTexture() const
Get the source texture of the sprite.
sf::Sprite::Sprite
Sprite()
Default constructor.
sf::Sprite::getGlobalBounds
FloatRect getGlobalBounds() const
Get the global bounding rectangle of the entity.
sf::Sprite::getLocalBounds
FloatRect getLocalBounds() const
Get the local bounding rectangle of the entity.
sf::Sprite::getColor
const Color & getColor() const
Get the global color of the sprite.
sf::Sprite::getTextureRect
const IntRect & getTextureRect() const
Get the sub-rectangle of the texture displayed by the sprite.
sf::Texture
Image living on the graphics card that can be used for drawing.
Definition: Texture.hpp:49
sf::Transformable
Decomposed transform defined by a position, a rotation and a scale.
Definition: Transformable.hpp:42
sf::Vertex
Define a point with color and texture coordinates.
Definition: Vertex.hpp:43