简体   繁体   中英

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. 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. 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. Could anyone suggest a way to implement a camera without using 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. 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. 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对象,绘制到该对象,然后以正确的偏移量在屏幕上绘画

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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