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-2024 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
31
37
38#include <array>
39
40
41namespace sf
42{
43class Texture;
44
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
#define SFML_GRAPHICS_API
Utility class for manipulating RGBA colors.
Definition Color.hpp:40
Abstract base class for objects that can be drawn to a render target.
Definition Drawable.hpp:44
Base class for all render targets (window, texture, ...)
Drawable representation of a texture, with its own transformations, color, etc.
Definition Sprite.hpp:51
Sprite(const Texture &texture, const IntRect &rectangle)
Construct the sprite from a sub-rectangle of a source texture.
const Texture & getTexture() const
Get the source texture of the sprite.
Sprite(const Texture &texture)
Construct the sprite from a source texture.
void setColor(Color color)
Set the global color of the sprite.
void setTexture(const Texture &texture, bool resetRect=false)
Change the source texture of the sprite.
void setTextureRect(const IntRect &rectangle)
Set the sub-rectangle of the texture that the sprite will display.
Sprite(const Texture &&texture)=delete
Disallow construction from a temporary texture.
void setTexture(const Texture &&texture, bool resetRect=false)=delete
Disallow setting from a temporary texture.
Color getColor() const
Get the global color of the sprite.
FloatRect getGlobalBounds() const
Get the global bounding rectangle of the entity.
Sprite(const Texture &&texture, const IntRect &rectangle)=delete
Disallow construction from a temporary texture.
FloatRect getLocalBounds() const
Get the local bounding rectangle of the entity.
const IntRect & getTextureRect() const
Get the sub-rectangle of the texture displayed by the sprite.
Image living on the graphics card that can be used for drawing.
Definition Texture.hpp:56
Decomposed transform defined by a position, a rotation and a scale.
Define the states used for drawing to a RenderTarget