XNA 将精灵捕捉到图块地图

发布于 2024-10-15 02:10:29 字数 180 浏览 1 评论 0原文

我正在寻找有关如何处理将精灵捕捉到图块地图的最佳选择。我正在尝试克隆楚楚火箭。如果你不了解这个游戏。这是一款基于图块的游戏,您可以在特定图块上放置箭头来引导地图周围的物体。因此,我需要始终将精灵捕捉到图块的中心,然后检测与占据整个图块或墙壁或其他障碍物的箭头的碰撞。关于检测这些东西的基本方法是什么的任何想法,因为我相信它需要不同类型的碰撞检测。

I'm looking for the best option on how to handle snapping sprites to a tilemap. I'm trying to make a Chu Chu Rocket clone. If you dont know the game. It is a tilebased game where you place arrows on a specfic tile to direct unts around the maps. So I need to snap the sprites to the center of the tile at all times and then detect a collision with either an arrow which takes up a whole tile or a wall or other obstruction. Any ideas on what the based way would be to detect those things since it would require different kinds of collision detection i believe.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幻想少年梦 2024-10-22 02:10:29

将精灵捕捉到图块的最简单方法是将它们绘制在图块的中心。碰撞检测可以在更新函数中通过检查关卡对象来完成。

class Mouse
{
  public int XTile;
  public int YTile;
  public int XDelta;
  public int YDelta;
} 

//in Update
if (Level[mouse.YTile][mouse.XTile] == Tiles.Arrow)
{
  //change mouse.XDelta and mouse.YDelta based on the direction of the arrow
}
if (Level[mouse.YTile + YDelta][mouse.XTile + XDelta] == Tiles.Wall)
{
  //change mouse.XDelta and mouse.YDelta based on wall rules
}

//in Draw
int tileSize = 32; //or whatever size tile you are using
spriteBatch.Draw(mouseSprite, new Vector2(mouse.XTile * tileSize, 
    mouse.YTile * tileSize), Color.White);

//or, if the mouseSprite doesn't take up the whole tile
int sizeDifference = tileSize - mouseSprite.Width;
spriteBatch.Draw(mouseSprite, new Vector2(mouse.XTile * tileSize + sizeDifference / 2f, 
    mouse.YTile * tileSize + sizeDifference / 2f), Color.White);

The easiest way to snap the sprites to a tile is to draw them centered at a tile. The collision detection can be done in your update function by checking against your level object.

class Mouse
{
  public int XTile;
  public int YTile;
  public int XDelta;
  public int YDelta;
} 

//in Update
if (Level[mouse.YTile][mouse.XTile] == Tiles.Arrow)
{
  //change mouse.XDelta and mouse.YDelta based on the direction of the arrow
}
if (Level[mouse.YTile + YDelta][mouse.XTile + XDelta] == Tiles.Wall)
{
  //change mouse.XDelta and mouse.YDelta based on wall rules
}

//in Draw
int tileSize = 32; //or whatever size tile you are using
spriteBatch.Draw(mouseSprite, new Vector2(mouse.XTile * tileSize, 
    mouse.YTile * tileSize), Color.White);

//or, if the mouseSprite doesn't take up the whole tile
int sizeDifference = tileSize - mouseSprite.Width;
spriteBatch.Draw(mouseSprite, new Vector2(mouse.XTile * tileSize + sizeDifference / 2f, 
    mouse.YTile * tileSize + sizeDifference / 2f), Color.White);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文