简体   繁体   English

Java 2D游戏摄像头,无需滚动世界

[英]Java 2D game camera without scrolling the world

I've just finished a month long project of building a very complex map / world editor for a 2D tile rpg type game. 我刚刚完成了一个月的项目,为2D瓷砖rpg类型的游戏构建非常复杂的地图/世界编辑器。 Now I'm at the point where I'd like to actually play the game and am in the process of creating the runtime implementation of the game using the maps, characters, and other things that were generated through the map editor. 现在,我正要实际玩游戏,并且正在使用通过地图编辑器生成的地图,角色和其他内容来创建游戏的运行时实现。 I know almost exactly what I am doing, aside from the camera. 除了相机外,我几乎完全知道我在做什么。 I cannot think of a way to make the camera work in a way similar to games like zelda(gameboy) (where the camera is fixed on the character) without scrolling the (x,y) values of every sprite and tile in my game everytime the player moves. 我想不出一种方法来使照相机以类似于zelda(gameboy)这样的游戏(照相机固定在角色上)的方式工作,而无需每次滚动游戏中每个精灵和图块的(x,y)值玩家移动。 I've looked into some game engines but I'm not convinced that is what I need, though I'm very willing to be wrong on that assumption. 我研究了一些游戏引擎,但是我不相信这是我所需要的,尽管我非常愿意在这个假设上犯错。 The entire game is done with images, there are no rendered shapes, which leads me to believe that I do not need to mess around with openGL to make the camera work as desired. 整个游戏都是用图像完成的,没有渲染的形状,这使我相信我不需要弄乱openGL即可使相机按需工作。 Could anyone suggest a way to implement a camera without using openGL? 有人可以建议不使用openGL来实现相机的方法吗? I'm not against using openGL but I'd rather not learn it if I dont need to as I am crunched for time already with other projects. 我不反对使用openGL,但我不想学习它,因为我已经在其他项目上花了很多时间。 Thank you for the suggestions. 感谢您的建议。

I would only draw what was visible in the characters camera area, thus you wouldn't need to move all of the sprites and such when your character moved. 我只会绘制在角色摄影机区域中可见的内容,因此,当角色移动时,您无需移动所有精灵。 However, anything on screen would have to be redrawn. 但是,屏幕上的所有内容都必须重绘。 Which wouldn't be too memory intensive and you could set it up with some sort of database system or even multidimensional arrays where it would only draw what was within the camera. 这不会占用太多内存,您可以使用某种数据库系统甚至多维数组来设置它,因为它只能绘制摄像机内部的内容。

For example, if you character is on tile 100(x) and 50(y) and the camera was a 7 by 7 grid of the tiles, all you would need to draw is whatever happened to be in the 48 tiles surrounding the player. 例如,如果您的角色位于图块100(x)和图块50(y)上,并且摄像机是7×7的图块网格,那么您所需要绘制的就是在玩家周围的48个图块中发生的一切。 This is how almost all tiled games do scrolling and isn't very hard on the memory. 这就是几乎所有平铺游戏进行滚动的方式,并且在内存上不是很困难。 You should be able to do this with minimal lag and not too much programming... depending on how you set up your tiles and their layering. 您应该能够以最小的滞后和不太多的编程来完成此操作……这取决于您如何设置图块及其分层。

一种简单的解决方案是创建一个Image对象,绘制到该对象,然后以正确的偏移量在屏幕上绘画

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM