commit 6ac01a78
Fixed ellipses
Changed files
| M | src/sagotmx/tmx_struct.h before |
| M | src/saland/Game.cpp before |
| M | src/saland/model/World.cpp before |
diff --git a/src/sagotmx/tmx_struct.h b/src/sagotmx/tmx_struct.h
index 6d680f6..30d5314 100644
--- a/src/sagotmx/tmx_struct.h
+++ b/src/sagotmx/tmx_struct.h
@@ -250,7 +250,7 @@ struct TileObject {
int y = 0;
int width = 0;
int height = 0;
- bool isEcplise = false;
+ bool isEllipse = false;
std::vector<std::pair<int,int> > polygon_points;
};
@@ -386,7 +386,7 @@ inline TileMap string2tilemap(const std::string& tmx_content) {
setValueFromAttribute(object_node, "y", to.y);
setValueFromAttribute(object_node, "width", to.width);
setValueFromAttribute(object_node, "height", to.height);
- getElement(object_node, "eclipse", to.isEcplise);
+ getElement(object_node, "ellipse", to.isEllipse);
bool isPolygon = false;
const auto& polygon = getElement(object_node, "polygon", isPolygon);
if (isPolygon) {
diff --git a/src/saland/Game.cpp b/src/saland/Game.cpp
index ab7d415..e4e52d2 100644
--- a/src/saland/Game.cpp
+++ b/src/saland/Game.cpp
@@ -74,15 +74,20 @@ static void DrawLayer(SDL_Renderer* renderer, SDL_Texture* texture, const sago::
static void DrawOjbectGroup (SDL_Renderer* renderer, const sago::tiled::TileMap& tm, size_t object_group, int topx, int topy) {
const sago::tiled::TileObjectGroup& group = tm.object_groups.at(object_group);
for (const sago::tiled::TileObject& o : group.objects) {
- rectangleRGBA(renderer, o.x - topx, o.y - topy,
- o.x+o.width-topx, o.y + o.height - topy, 255, 255, 0, 255);
- if (o.polygon_points.size() > 0) {
+ if (o.isEllipse) {
+ ellipseRGBA(renderer, (o.x+o.width/2) - topx, (o.y+o.height/2) - topy, o.width/2, o.height/2,255,255,0,255);
+ }
+ else if (o.polygon_points.size() > 0) {
for (size_t i = 0; i < o.polygon_points.size(); ++i) {
std::pair<int, int> first = o.polygon_points.at(i);
std::pair<int, int> second = (i+1 < o.polygon_points.size()) ? o.polygon_points.at(i+1) : o.polygon_points.at(0);
lineRGBA(renderer, first.first +o.x - topx, first.second + o.y - topy, second.first + o.x - topx, second.second + o.y - topy, 255, 255, 0, 255);
}
}
+ else {
+ rectangleRGBA(renderer, o.x - topx, o.y - topy,
+ o.x+o.width-topx, o.y + o.height - topy, 255, 255, 0, 255);
+ }
}
}
diff --git a/src/saland/model/World.cpp b/src/saland/model/World.cpp
index 6f056e1..f6ded4e 100644
--- a/src/saland/model/World.cpp
+++ b/src/saland/model/World.cpp
@@ -96,7 +96,7 @@ void World::init(std::shared_ptr<b2World>& world) {
const std::vector<sago::tiled::TileObjectGroup>& object_groups = tm.object_groups;
for (const auto& group : object_groups) {
for (const auto& item : group.objects) {
- if (item.isEcplise) {
+ if (item.isEllipse) {
continue;
}
if (item.x > 0 && item.y > 0 && item.width > 0 && item.height > 0) {