SFML - Simple and Fast Multimedia Library

SFML 3.0.1

- Main Page
- Topics
- Namespaces
- Classes
- Files

- File List
- File Members

Loading...
Searching...
No Matches
Sprite.hpp
Go to the documentation of this file.
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2025 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#pragma once
26
28// Headers
30#include <SFML/Graphics/Export.hpp>
31
32#include <SFML/Graphics/Drawable.hpp>
33#include <SFML/Graphics/Rect.hpp>
34#include <SFML/Graphics/RenderStates.hpp>
35#include <SFML/Graphics/Transformable.hpp>
36#include <SFML/Graphics/Vertex.hpp>
37
38#include <array>
39
40
41namespace sf
42{
43class Texture;
44
50 class SFML_GRAPHICS_API Sprite : public Drawable, public Transformable
51{
52public:
61 explicit Sprite(const Texture& texture);
62
67 explicit Sprite(const Texture&& texture) = delete;
68
78 Sprite(const Texture& texture, const IntRect& rectangle);
79
84 Sprite(const Texture&& texture, const IntRect& rectangle) = delete;
85
105 void setTexture(const Texture& texture, bool resetRect = false);
106
111 void setTexture(const Texture&& texture, bool resetRect = false) = delete;
112
125 void setTextureRect(const IntRect& rectangle);
126
140 void setColor(Color color);
141
153 [[nodiscard]] const Texture& getTexture() const;
154
163 [[nodiscard]] const IntRect& getTextureRect() const;
164
173 [[nodiscard]] Color getColor() const;
174
187 [[nodiscard]] FloatRect getLocalBounds() const;
188
201 [[nodiscard]] FloatRect getGlobalBounds() const;
202
203private:
211 void draw(RenderTarget& target, RenderStates states) const override;
212
217 void updateVertices();
218
220 // Member data
222 std::array<Vertex, 4> m_vertices;
223 const Texture* m_texture;
224 IntRect m_textureRect;
225};
226
227} // namespace sf
228
229
Drawable.hpp
Export.hpp
SFML_GRAPHICS_API
#define SFML_GRAPHICS_API
Definition Graphics/Export.hpp:42
Rect.hpp
RenderStates.hpp
Transformable.hpp
Vertex.hpp
sf::Color
Utility class for manipulating RGBA colors.
Definition Color.hpp:40
sf::Drawable
Abstract base class for objects that can be drawn to a render target.
Definition Drawable.hpp:44
sf::Drawable::RenderTarget
friend class RenderTarget
Definition Drawable.hpp:53
sf::Sprite::Sprite
Sprite(const Texture &texture, const IntRect &rectangle)
Construct the sprite from a sub-rectangle of a source texture.
sf::Sprite::getTexture
const Texture & getTexture() const
Get the source texture of the sprite.
sf::Sprite::Sprite
Sprite(const Texture &texture)
Construct the sprite from a source texture.
sf::Sprite::setColor
void setColor(Color color)
Set the global color of the sprite.
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::Sprite
Sprite(const Texture &&texture)=delete
Disallow construction from a temporary texture.
sf::Sprite::setTexture
void setTexture(const Texture &&texture, bool resetRect=false)=delete
Disallow setting from a temporary texture.
sf::Sprite::getColor
Color getColor() const
Get the global color of the sprite.
sf::Sprite::getGlobalBounds
FloatRect getGlobalBounds() const
Get the global bounding rectangle of the entity.
sf::Sprite::Sprite
Sprite(const Texture &&texture, const IntRect &rectangle)=delete
Disallow construction from a temporary texture.
sf::Sprite::getLocalBounds
FloatRect getLocalBounds() const
Get the local bounding rectangle of the entity.
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:56
sf::Transformable::Transformable
Transformable()=default
Default constructor.
sf
Definition AudioResource.hpp:36
sf::FloatRect
Rect< float > FloatRect
Definition Rect.hpp:147
sf::IntRect
Rect< int > IntRect
Definition Rect.hpp:146
sf::RenderStates
Define the states used for drawing to a RenderTarget
Definition RenderStates.hpp:48