相机为2d游戏 [英] Camera for 2d game

查看:215
本文介绍了相机为2d游戏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在制作一个很棒的(在我看来)僵尸游戏,我需要知道制作相机的好方法。我正在使用Slick2d库和MarteEngine for java。

I'm currently making an awesome (in my mind) zombie game and I need to know a good way to make a camera. I am using the Slick2d library along with MarteEngine for java.

我对java很新,直接跳进了一个库才真正深入到摇摆之中这样可能缺乏图形知识。我读了一个教程,你不能在地图上实际移动游戏的窗口,所以你需要移动地图和物体,使它看起来像是相机正在移动。

I'm kinda new to java and jumped straight into a library before really getting deep into swing and such so this is probably a lack of graphics knowledge. I read on a tutorial that you can't actually move the window of the game on the map so instead you need to move the map and objects to make it seem like the camera is moving.

如果我这样做,看起来它会非常耗费资源。我将不得不遍历每个僵尸,幸存者,物体,hitbox等移动他们的坐标。我已经尝试了一次这种方法,事情并没有真正以同样的速度移动。这可能是因为我以不同的更新速度处理它。

If I was to do it this way it seems like it would be very resource intensive. I would have to loop through every zombie, survivor, object, hitbox, etc to move their coordinates. I've already tried this method once and things weren't really moving the same speed. That may have been due to me handling it with different update speeds.

我看过使用graphics.translate的一些事情,但我真的不明白。所以..任何有关移动相机的建议都会很棒!在此先感谢。

I've seen a few things on using graphics.translate but I don't really understand it. So.. any suggestions to making a camera move would be awesome! Thanks in advance.

推荐答案

你绝对可以移动相机。请参阅我对此问题的回答,解释如何移动相机,渲染相对于所述相机的世界,以及一些其他有用的提示,了解如何执行此操作以及如何在相机移动时决定在屏幕上绘制

You can definitely move the camera. See my answer to this question explaining how to move the camera, render the world relative to said camera, and some other useful tips on how to do this and how to decide what to draw on the screen as the camera moves.

虽然完全有可能使用 translate(x,y),但这并不能解决裁剪问题(如何知道该怎么做)画在屏幕上),这不是一个全部。此外,当你考虑它时,翻译表面和移动相机之间真的没什么区别。这一切都是相对的,只要像素在正确的方向上移动,如果你相对于世界移动相机或相对于相机移动世界并不重要 - 它们是基本上是相同的操作。

While it's totally possible to use translate(x, y), that alone doesn't solve clipping issues (how to know what to draw on the screen), and it's not a catch all. Also, when you think about it, there's really not much of a difference between translating the surface and moving the camera. It's all relative, and so long as the pixels are moving in the right direction, it doesn't really matter if you're "moving the camera relative to the world" or "moving the world relative to the camera" - they're essentially the same operation.

就Swing而言,很高兴你没有从那里开始。 Swing专为具有窗口,菜单,按钮,复杂事件系统等的桌面应用程序而设计。出于多种原因,Swing对于游戏来说是可怕的,其中最重要的是渲染管道在Swing中的工作方式;它适用于桌面应用程序,但对于游戏和大多数需要实时和图形密集的渲染类型而言,它们变得绝望。这一切都没关系,因为Swing不是为解决游戏开发者的问题而构建的。

As far as Swing is concerned, be glad you didn't start there. Swing is designed for desktop applications with windows, menus, buttons, complex event systems, and the like. For a number of reasons Swing is terrible for games, not the least of which is the way the rendering pipeline works in Swing; it's fine for desktop apps, but becomes a pit of despair for games and most types of rendering that need to be real-time, and graphics intensive. This is all okay because Swing wasn't built to solve the problems of game developers anyway.

这篇关于相机为2d游戏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆