Gamedev Framework (gf) 0.22.0
A C++17 framework for 2D games
Tileset.h
1/*
2 * Gamedev Framework (gf)
3 * Copyright (C) 2016-2022 Julien Bernard
4 *
5 * This software is provided 'as-is', without any express or implied
6 * warranty. In no event will the authors be held liable for any damages
7 * 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
11 * freely, subject to the following restrictions:
12 *
13 * 1. The origin of this software must not be misrepresented; you must not
14 * claim that you wrote the original software. If you use this software
15 * in a product, an acknowledgment in the product documentation would be
16 * appreciated but is not required.
17 * 2. Altered source versions must be plainly marked as such, and must not be
18 * misrepresented as being the original software.
19 * 3. This notice may not be removed or altered from any source distribution.
20 */
21#ifndef GF_TILESET_H
22#define GF_TILESET_H
23
24#include "GraphicsApi.h"
25#include "Texture.h"
26#include "Vector.h"
27
28namespace gf {
29#ifndef DOXYGEN_SHOULD_SKIP_THIS
30inline namespace v1 {
31#endif
32
48 class GF_GRAPHICS_API Tileset {
49 public:
51
64 void setTexture(const Texture& texture);
65
75 const Texture& getTexture() const {
76 return *m_texture;
77 }
78
86 bool hasTexture() const {
87 return m_texture != nullptr;
88 }
89
98
105 void setTileSize(Vector2i tileSize);
106
114 return m_tileSize;
115 }
116
123 void setMargin(int margin) {
124 setMargin({ margin, margin });
125 }
126
133 void setMargin(Vector2i margin);
134
142 return m_margin;
143 }
144
151 void setSpacing(int spacing) {
152 setSpacing({ spacing, spacing });
153 }
154
161 void setSpacing(Vector2i spacing);
162
170 return m_spacing;
171 }
172
179 void setOffset(Vector2i offset);
180
188 return m_offset;
189 }
190
197 return m_size;
198 }
199
207
215
216 private:
217 void updateSize();
218
219 private:
220 const Texture *m_texture;
221 Vector2i m_tileSize;
222 Vector2i m_margin;
223 Vector2i m_spacing;
224 Vector2i m_offset;
225 Vector2i m_size;
226 };
227
228#ifndef DOXYGEN_SHOULD_SKIP_THIS
229}
230#endif
231}
232
233#endif // GF_TILESET_H
A texture for colored images.
Definition: Texture.h:313
A tileset.
Definition: Tileset.h:48
void setMargin(int margin)
Set the margin of the tileset.
Definition: Tileset.h:123
void setTexture(const Texture &texture)
Change the source texture of the tileset.
void setSpacing(Vector2i spacing)
Set the spacing of the tileset.
void setOffset(Vector2i offset)
Set the offset of the tileset.
Vector2i getTileSize() const
Get the tile size in the tileset.
Definition: Tileset.h:113
RectF computeTextureCoords(int tile) const
Get the texture coordinates for a tile.
Vector2i getOffset() const
Get the offset of the tileset.
Definition: Tileset.h:187
const Texture & getTexture() const
Get the source texture of the tileset.
Definition: Tileset.h:75
Vector2i getMargin() const
Get the margin of the tileset.
Definition: Tileset.h:141
RectF computeTextureCoords(Vector2i coords) const
Get the texture coordinates for a tile.
Vector2i getSize() const
Get the size of the tileset.
Definition: Tileset.h:196
void unsetTexture()
Unset the source texture of the tile layer.
void setMargin(Vector2i margin)
Set the margin of the tileset.
Vector2i getSpacing() const
Get the spacing of the tileset.
Definition: Tileset.h:169
bool hasTexture() const
Check if a texture is set.
Definition: Tileset.h:86
void setSpacing(int spacing)
Set the spacing of the tileset.
Definition: Tileset.h:151
void setTileSize(Vector2i tileSize)
Set the tile size in the tileset.
The namespace for gf classes.