Show More
Commit Description:
Add ImageMap class I left out by mistake.
Commit Description:
Add ImageMap class I left out by mistake.
References:
File last commit:
Show/Diff file:
Action:
isometric-park-fna/ImageMap.cs
69 lines | 1.9 KiB | text/x-csharp | CSharpLexer
69 lines | 1.9 KiB | text/x-csharp | CSharpLexer
r133 | ||||
using System; | ||||
using Num = System.Numerics; | ||||
using Microsoft.Xna.Framework; | ||||
using Microsoft.Xna.Framework.Graphics; | ||||
namespace isometricparkfna | ||||
{ | ||||
public class ImageMap | ||||
{ | ||||
static public Texture2D ImageMapTexture; | ||||
public int TileWidth; | ||||
public int TileHeight; | ||||
public ImageMap(int tileWidth, int tileHeight ) | ||||
{ | ||||
this.TileHeight = tileHeight; | ||||
this.TileWidth = tileWidth; | ||||
} | ||||
public Rectangle GetSourceRectangle(int tileIndex) | ||||
{ | ||||
int tileY = tileIndex / (ImageMapTexture.Width / TileWidth); | ||||
int tileX = tileIndex % (ImageMapTexture.Width / TileWidth); | ||||
return new Rectangle(tileX * TileWidth, tileY * TileHeight, TileWidth, TileHeight); | ||||
} | ||||
public Num.Vector2 GetSourceUVStart(int tileIndex) | ||||
{ | ||||
int tileX = tileIndex % (ImageMapTexture.Width / TileWidth); | ||||
int tileY = tileIndex / (ImageMapTexture.Width / TileWidth); | ||||
int imageMapX = (tileX) * TileWidth; | ||||
int imageMapY = (tileY) * TileHeight; | ||||
return new Num.Vector2( ((float)imageMapX)/ImageMapTexture.Width, | ||||
((float)imageMapY)/ImageMapTexture.Height); | ||||
} | ||||
public Num.Vector2 GetSourceUVEnd(int tileIndex) | ||||
{ | ||||
int tileX = tileIndex % (ImageMapTexture.Width / TileWidth); | ||||
int tileY = tileIndex / (ImageMapTexture.Width / TileWidth); | ||||
int imageMapX = (tileX+1) * TileWidth; | ||||
int imageMapY = (tileY+1) * TileHeight; | ||||
return new Num.Vector2( ((float)imageMapX)/ImageMapTexture.Width, | ||||
((float)imageMapY)/ImageMapTexture.Height); | ||||
} | ||||
public Rectangle GetExtendedSourceRectangle(int tileIndex, int height) | ||||
{ | ||||
int tileY = tileIndex / (ImageMapTexture.Width / TileWidth); | ||||
int tileX = tileIndex % (ImageMapTexture.Width / TileWidth); | ||||
return new Rectangle(tileX * TileWidth, tileY * TileHeight, TileWidth, TileHeight*height); | ||||
} | ||||
} | ||||
} | ||||