Sprite.hpp
1// Copyright 2019 Arthur Sonzogni. All rights reserved.
2// Use of this source code is governed by the MIT license that can be found in
3// the LICENSE file.
4
5#ifndef SMK_SPRITE_HPP
6#define SMK_SPRITE_HPP
7
8#include <smk/Rectangle.hpp>
9#include <smk/RenderState.hpp>
10#include <smk/Texture.hpp>
11#include <smk/Transformable.hpp>
12
13namespace smk {
14
15class Framebuffer;
16
17/// @example sprite.cpp
18/// @example sprite_move.cpp
19/// @example texture_subrectangle.cpp
20
21/// A Drawable specialised in displaying rectangular texture.
22///
23/// Example:
24/// -------
25/// ~~~cpp
26/// auto sprite = smk::Sprite(texture_ball);
27///
28/// sprite.SetCenter(32,32);
29/// sprite.SetPosition(player.x, player.y);
30/// sprite.SetRotation(player.rotation);
31///
32/// window.Draw(sprite);
33/// ~~~
34class Sprite : public Transformable {
35 public:
36 Sprite() = default;
37 Sprite(const Texture& texture);
38 Sprite(const Texture& texture, const Rectangle rectangle);
39 explicit Sprite(Framebuffer& framebuffer);
40
41 // Movable and copyable.
42 Sprite(Sprite&&) = default;
43 Sprite(const Sprite&) = default;
44 Sprite& operator=(Sprite&&) = default;
45 Sprite& operator=(const Sprite&) = default;
46
47 // Modify the sprite.
48 void SetTexture(const Texture& texture);
49 void SetTextureRectangle(const Rectangle& rectangle);
50};
51
52} // namespace smk
53
54#endif /* end of include guard: SMK_SPRITE_HPP */
An off-screen drawable area. You can also draw it later in a smk::Sprite.
Definition: Framebuffer.hpp:18
void SetTexture(const Texture &texture)
Update the sprite's texture.
Definition: Sprite.cpp:50
void SetTextureRectangle(const Rectangle &rectangle)
Update the sprite texture area.
Definition: Sprite.cpp:63