2D 平铺相机?

发布于 2024-11-06 10:11:51 字数 642 浏览 0 评论 0原文

嘿大家。在这里快速提问。我试图将相机保持在玩家的中心,但在下面的代码中,可以说相机仍然在移动。关于如何让它留在一个地方有什么想法吗?

for(int across = player.PlayerX-5; across < player.PlayerX+5; across++) 
        {
          for(int vert = player.PlayerY-5; vert < player.PlayerX+5; vert++)
          {
            //double RANDOM = Math.random();
            if(across < 0 || vert < 0)
            {
            }
            else if(levONE.A[vert][across] == 1)
            {
              g.drawImage(Floor,across*32,vert*32,this);

            else if(levONE.A[vert][across] == 0)
              g.drawImage(Wall,across*32,vert*32,this);
          }
        }

Hey all. Quick question here. I'm trying to keep the camera centered on the player, but in the code below, the camera so to speak still moves. Any ideas on how to make it stay in one spot?

for(int across = player.PlayerX-5; across < player.PlayerX+5; across++) 
        {
          for(int vert = player.PlayerY-5; vert < player.PlayerX+5; vert++)
          {
            //double RANDOM = Math.random();
            if(across < 0 || vert < 0)
            {
            }
            else if(levONE.A[vert][across] == 1)
            {
              g.drawImage(Floor,across*32,vert*32,this);

            else if(levONE.A[vert][across] == 0)
              g.drawImage(Wall,across*32,vert*32,this);
          }
        }

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

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

发布评论

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

评论(1

遗弃M 2024-11-13 10:11:51

看起来您有一个带有图块地图的自上而下的 2D 游戏。您正在尝试渲染一个 9x9 的正方形,而玩家位于中间?

在“else if(levONE.A[vert][across] == 1)”之后有一些括号奇怪的地方,但我认为这不会在当前状态下编译?

除了代码看起来不错之外,我可能会首先添加打印语句,以确保您获得的数据符合您的预期。像......

for(int across = player.PlayerX-5; across < player.PlayerX+5; across++) 
{
  for(int vert = player.PlayerY-5; vert < player.PlayerX+5; vert++)
  {
    //double RANDOM = Math.random();
    if(across < 0 || vert < 0)  //might want to check the 'high' bounds here too
    {
    }
    else if(levONE.A[vert][across] == 1)
    {
      g.drawImage(Floor,across*32,vert*32,this);
    }
    else if(levONE.A[vert][across] == 0) 
    {
      g.drawImage(Wall,across*32,vert*32,this);
    }

    //print ("%d ", levONE.A[vert][across]);
  }
  //print ("\n");
}

应该给你一个很好的网格来使用

0 0 0 0 0 0 0 0
1 1 0 0 1 1 1 1
etc..

It looks like you have a top-down 2d game with a tile map. You are trying to render a 9x9 square with the player in the middle?

You have some bracket odd-ness after the 'else if(levONE.A[vert][across] == 1)' But I think that wouldn't compile in its current state?

Other than that the code looks good, I might start by adding print statements to ensure the data you are getting is what you expect. Something like...

for(int across = player.PlayerX-5; across < player.PlayerX+5; across++) 
{
  for(int vert = player.PlayerY-5; vert < player.PlayerX+5; vert++)
  {
    //double RANDOM = Math.random();
    if(across < 0 || vert < 0)  //might want to check the 'high' bounds here too
    {
    }
    else if(levONE.A[vert][across] == 1)
    {
      g.drawImage(Floor,across*32,vert*32,this);
    }
    else if(levONE.A[vert][across] == 0) 
    {
      g.drawImage(Wall,across*32,vert*32,this);
    }

    //print ("%d ", levONE.A[vert][across]);
  }
  //print ("\n");
}

Should give you a nice grid to work with

0 0 0 0 0 0 0 0
1 1 0 0 1 1 1 1
etc..
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文