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

查看:40
本文介绍了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 有点陌生,在真正深入了解 Swing 之前直接跳入了一个库,所以这可能是缺乏图形知识.我在一个教程中读到,您实际上无法在地图上移动游戏窗口,因此您需要移动地图和对象以使其看起来像相机在移动.

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天全站免登陆