Skip to content

Commit

Permalink
Small adjustments
Browse files Browse the repository at this point in the history
Seems to be no reason to round the polygons to pixels, since the
collision shape is defined by an array of floating point Vector2.
  • Loading branch information
bjorn committed Jan 30, 2024
1 parent f95af2d commit aff6170
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/plugins/tscn/tscnplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,9 @@ static bool exportTileCollisions(QFileDevice *device, const Tile *tile,
if (const auto objectGroup = tile->objectGroup()) {
int polygonId = 0;

const auto centerX = tile->width() / 2;
const auto centerY = tile->height() / 2;

for (const auto object : objectGroup->objects()) {
const auto shape = object->shape();

Expand All @@ -435,9 +438,6 @@ static bool exportTileCollisions(QFileDevice *device, const Tile *tile,

foundCollisions = true;

const auto centerX = tile->width() / 2;
const auto centerY = tile->height() / 2;

device->write(formatByteString(
"%1/physics_layer_0/polygon_%2/points = PackedVector2Array(",
tileName, polygonId));
Expand All @@ -458,13 +458,12 @@ static bool exportTileCollisions(QFileDevice *device, const Tile *tile,
break;
}
case MapObject::Polygon: {
auto polygon = object->polygon().toPolygon();
bool first = true;
for (auto point : polygon) {
for (auto point : object->polygon()) {
if (!first)
device->write(", ");
double x = object->x() + point.x() - centerX;
double y = object->y() + point.y() - centerY;
auto x = object->x() + point.x() - centerX;
auto y = object->y() + point.y() - centerY;
flipState(x, y, flippedState);
device->write(formatByteString("%1, %2", x, y));
first = false;
Expand Down

0 comments on commit aff6170

Please sign in to comment.