mirror of
https://github.com/AlexMacocian/MonoGame.Extended.git
synced 2026-07-24 12:06:37 +00:00
When I released #480 to fix some texture alignment issues, I failed to check the variable types for the math being done. With my original fix by removing the `+ 0.5f` overdraw, the math changed from `float` division to `int` division. I'm now recasting for `float` division as it should be! My bad!!
47 lines
1.7 KiB
C#
47 lines
1.7 KiB
C#
using System;
|
|
using Microsoft.Xna.Framework;
|
|
|
|
namespace MonoGame.Extended.Tiled
|
|
{
|
|
public struct TiledMapTilesetTileAnimationFrame
|
|
{
|
|
public readonly int LocalTileIdentifier;
|
|
public readonly TimeSpan Duration;
|
|
public readonly Vector2[] TextureCoordinates;
|
|
|
|
internal TiledMapTilesetTileAnimationFrame(TiledMapTileset tileset, int localTileIdentifier, int durationInMilliseconds)
|
|
{
|
|
LocalTileIdentifier = localTileIdentifier;
|
|
Duration = new TimeSpan(0, 0, 0, 0, durationInMilliseconds);
|
|
TextureCoordinates = new Vector2[4];
|
|
CreateTextureCoordinates(tileset);
|
|
}
|
|
|
|
private void CreateTextureCoordinates(TiledMapTileset tileset)
|
|
{
|
|
var sourceRectangle = tileset.GetTileRegion(LocalTileIdentifier);
|
|
var texture = tileset.Texture;
|
|
var texelLeft = (float)sourceRectangle.X / texture.Width;
|
|
var texelTop = (float)sourceRectangle.Y / texture.Height;
|
|
var texelRight = (sourceRectangle.X + sourceRectangle.Width) / (float)texture.Width;
|
|
var texelBottom = (sourceRectangle.Y + sourceRectangle.Height) / (float)texture.Height;
|
|
|
|
TextureCoordinates[0].X = texelLeft;
|
|
TextureCoordinates[0].Y = texelTop;
|
|
|
|
TextureCoordinates[1].X = texelRight;
|
|
TextureCoordinates[1].Y = texelTop;
|
|
|
|
TextureCoordinates[2].X = texelLeft;
|
|
TextureCoordinates[2].Y = texelBottom;
|
|
|
|
TextureCoordinates[3].X = texelRight;
|
|
TextureCoordinates[3].Y = texelBottom;
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"{LocalTileIdentifier}:{Duration}";
|
|
}
|
|
}
|
|
} |