2D 平铺相机?
嘿大家。在这里快速提问。我试图将相机保持在玩家的中心,但在下面的代码中,可以说相机仍然在移动。关于如何让它留在一个地方有什么想法吗?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您有一个带有图块地图的自上而下的 2D 游戏。您正在尝试渲染一个 9x9 的正方形,而玩家位于中间?
在“else if(levONE.A[vert][across] == 1)”之后有一些括号奇怪的地方,但我认为这不会在当前状态下编译?
除了代码看起来不错之外,我可能会首先添加打印语句,以确保您获得的数据符合您的预期。像......
应该给你一个很好的网格来使用
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...
Should give you a nice grid to work with