summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Dombrowski <stefan@uni-bonn.de>2010-12-05 19:30:53 +0100
committerStefan Dombrowski <stefan@uni-bonn.de>2010-12-05 19:30:53 +0100
commitf622cf4c545033e25fde7f3e1105cdf2118d7016 (patch)
tree2f4a69193a1d37716e8b7fdac1d04b2c1fba6268
parentf2b8d02dc560528f6854a339c1974d761daabc70 (diff)
downloadmana-client-f622cf4c545033e25fde7f3e1105cdf2118d7016.tar.gz
mana-client-f622cf4c545033e25fde7f3e1105cdf2118d7016.tar.bz2
mana-client-f622cf4c545033e25fde7f3e1105cdf2118d7016.tar.xz
mana-client-f622cf4c545033e25fde7f3e1105cdf2118d7016.zip
Add support for tiles with spacing
Now the map from the Mana server's example data is shown properly. Reviewed-by: Jaxad0127
-rw-r--r--src/resources/imageset.cpp6
-rw-r--r--src/resources/imageset.h2
-rw-r--r--src/resources/mapreader.cpp5
-rw-r--r--src/tileset.h4
4 files changed, 10 insertions, 7 deletions
diff --git a/src/resources/imageset.cpp b/src/resources/imageset.cpp
index bd28cd6e..d33fac32 100644
--- a/src/resources/imageset.cpp
+++ b/src/resources/imageset.cpp
@@ -27,11 +27,11 @@
#include "utils/dtor.h"
-ImageSet::ImageSet(Image *img, int width, int height)
+ImageSet::ImageSet(Image *img, int width, int height, int margin, int spacing)
{
- for (int y = 0; y + height <= img->getHeight(); y += height)
+ for (int y = margin; y + height <= img->getHeight() - margin; y += height + spacing)
{
- for (int x = 0; x + width <= img->getWidth(); x += width)
+ for (int x = margin; x + width <= img->getWidth() - margin; x += width + spacing)
{
mImages.push_back(img->getSubImage(x, y, width, height));
}
diff --git a/src/resources/imageset.h b/src/resources/imageset.h
index 763b9880..3289788f 100644
--- a/src/resources/imageset.h
+++ b/src/resources/imageset.h
@@ -37,7 +37,7 @@ class ImageSet : public Resource
/**
* Cuts the passed image in a grid of sub images.
*/
- ImageSet(Image *img, int w, int h);
+ ImageSet(Image *img, int w, int h, int margin = 0, int spacing = 0);
/**
* Destructor.
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index b30bec0a..28feaba8 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -392,6 +392,8 @@ Tileset *MapReader::readTileset(xmlNodePtr node, const std::string &path,
Map *map)
{
int firstGid = XML::getProperty(node, "firstgid", 0);
+ int margin = XML::getProperty(node, "margin", 0);
+ int spacing = XML::getProperty(node, "spacing", 0);
XML::Document* doc = NULL;
Tileset *set = NULL;
std::string pathDir(path);
@@ -426,7 +428,8 @@ Tileset *MapReader::readTileset(xmlNodePtr node, const std::string &path,
if (tilebmp)
{
- set = new Tileset(tilebmp, tw, th, firstGid);
+ set = new Tileset(tilebmp, tw, th, firstGid, margin,
+ spacing);
tilebmp->decRef();
}
else
diff --git a/src/tileset.h b/src/tileset.h
index 56bc4547..6c2ee394 100644
--- a/src/tileset.h
+++ b/src/tileset.h
@@ -33,8 +33,8 @@ class Tileset : public ImageSet
/**
* Constructor.
*/
- Tileset(Image *img, int w, int h, int firstGid):
- ImageSet(img, w, h),
+ Tileset(Image *img, int w, int h, int firstGid, int margin, int spacing):
+ ImageSet(img, w, h, margin, spacing),
mFirstGid(firstGid)
{
}