1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-12-25 01:39:23 +01:00

allowed the GetArea extension to calculate flipping

This commit is contained in:
Ell 2021-03-12 20:22:36 +01:00
parent 45fc12b0cb
commit 0ddb4afc3f
2 changed files with 13 additions and 12 deletions

View file

@ -5,6 +5,7 @@ using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MonoGame.Extended;
using MonoGame.Extended.Tiled;
using static MonoGame.Extended.Tiled.TiledMapTileFlipFlags;
using ColorHelper = MLEM.Extensions.ColorHelper;
namespace MLEM.Extended.Tiled {
@ -268,11 +269,18 @@ namespace MLEM.Extended.Tiled {
/// <param name="obj">The object whose area to get</param>
/// <param name="map">The map</param>
/// <param name="position">The position to add to the object's position</param>
/// <param name="flipFlags">The flipping of the tile that this object belongs to. If set, the returned area will be "flipped" in the tile's space so that it matches the flip flags.</param>
/// <returns>The area that the tile covers</returns>
public static RectangleF GetArea(this TiledMapObject obj, TiledMap map, Vector2? position = null) {
public static RectangleF GetArea(this TiledMapObject obj, TiledMap map, Vector2? position = null, TiledMapTileFlipFlags flipFlags = None) {
var tileSize = map.GetTileSize();
var pos = position ?? Vector2.Zero;
return new RectangleF(obj.Position / tileSize + pos, obj.Size / tileSize);
var area = new RectangleF(obj.Position / tileSize, obj.Size / tileSize);
if (flipFlags.HasFlag(FlipHorizontally))
area.X = 1 - area.X - area.Width;
if (flipFlags.HasFlag(FlipVertically))
area.Y = 1 - area.Y - area.Height;
if (position != null)
area.Offset(position.Value);
return area;
}
/// <summary>

View file

@ -141,15 +141,8 @@ namespace MLEM.Extended.Tiled {
/// <param name="collisions">The list of collisions to add to</param>
/// <param name="tile">The tile's collision information</param>
public static void DefaultCollectCollisions(List<RectangleF> collisions, TileCollisionInfo tile) {
foreach (var obj in tile.TilesetTile.Objects) {
var area = obj.GetArea(tile.Map);
if (tile.Tile.IsFlippedHorizontally)
area.X = 1 - area.X - area.Width;
if (tile.Tile.IsFlippedVertically)
area.Y = 1 - area.Y - area.Height;
area.Offset(tile.Position);
collisions.Add(area);
}
foreach (var obj in tile.TilesetTile.Objects)
collisions.Add(obj.GetArea(tile.Map, tile.Position, tile.Tile.Flags));
}
/// <summary>