Documentation de SFML 2.6.0

Attention: cette page se réfère à une ancienne version de SFML. Cliquez ici pour passer à la dernière version.
Loading...
Searching...
No Matches
Sprite.hpp
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2023 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
38namespace sf
39{
40class Texture;
41
47class SFML_GRAPHICS_API Sprite : public Drawable, public Transformable
48{
49public:
50
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
177
191
192private:
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
Utility class for manipulating RGBA colors.
Definition: Color.hpp:41
Abstract base class for objects that can be drawn to a render target.
Definition: Drawable.hpp:45
Define the states used for drawing to a RenderTarget.
Base class for all render targets (window, texture, ...)
Drawable representation of a texture, with its own transformations, color, etc.
Definition: Sprite.hpp:48
Sprite(const Texture &texture, const IntRect &rectangle)
Construct the sprite from a sub-rectangle of a source texture.
void setColor(const Color &color)
Set the global color of the sprite.
Sprite(const Texture &texture)
Construct the sprite from a source texture.
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.
const Texture * getTexture() const
Get the source texture of the sprite.
Sprite()
Default constructor.
FloatRect getGlobalBounds() const
Get the global bounding rectangle of the entity.
FloatRect getLocalBounds() const
Get the local bounding rectangle of the entity.
const Color & getColor() const
Get the global color of the sprite.
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:49
Decomposed transform defined by a position, a rotation and a scale.
Define a point with color and texture coordinates.
Definition: Vertex.hpp:43