I am writing a 2d game in java. The game mechanics are similar to the Pokémon game boy advance series e.g. fire red, ruby, diamond and so on.

I need a way to draw a huge map maybe 5000 by 5000 pixels and then load individual in game sprites to across the entirety of the map, like rendering a scene. Game sprites would be things like terrain objects, trees, rocks, bushes, also houses, castles, NPC's and so on. But i also need to implement some kind of camera view class that focuses on the player. the camera view class needs to follow the characters movements throughout the game map but it also needs to clip the rest of the map away from the user's field of view, so that the user can only see the arbitrary proximity adjacent to the player's sprite. The proximity's range could be something like 500 pixels in every direction around the player’s sprite. On top of this, i need to implement an independent resolution for the game world so that the game view will be uniform on all screen sizes and screen resolutions.

I know that this does sound like a handful and may fall under the category of multiple questions, but the questions are all related and any advice would be very much appreciated. I don’t need a full source code listing but maybe some pointers to effective java API classes that could make doing what i need to do a lot simpler. Also any algorithmic/ design advice would greatly benefit me as well.

example of what i am trying to do in source code form below

package myPackage;

 * The Purpose of GameView is to: Render a scene using Scene class, Create a
 * clipping pane using CameraView class, and finally instantiate a coordinate
 * grid using Path class.
 * Once all of these things have been done, GameView class should then be
 * instantiated and used jointly with its helper classes. CameraView should be
 * used as the main drawing image. CameraView is the the window to the game
 * world.Scene passes data constantly to CameraView so that the entire map flows
 * smoothly. Path uses the x and y coordinates from camera view to construct
 * cells for path finding algorithms.

public class GameView {

    // Scene is a helper class to game view. it renders the entire map to memory
    // for the camera view.
    Scene scene;

    // Camera View is a helper class to game view. It clips the Scene into a
    // small image that follows the players coordinates.
    CameraView Camera;

    // Path is a helper class to game view. It observes and calculates the
    // coordinates of camera view and divides them into Grids/Cells for Path
    // finding.
    Path path;

    // this represents the player and has a getSprite() method that will return
    // the current frame column row combination of the passed sprite sheet.
    Sprite player;

2 Answers 2


I don't think Java will be able to deal directly with an image this size very effectively, especially if the intended target is online. I think you would do well to construct a run-time view at screen resolution from multiple tiles at precomputed multiple resolutions.

  • \$\begingroup\$ When you say "construct a run-time view at screen resolution from multiple tiles at precomputed multiple resolutions." what exactly do you mean? \$\endgroup\$
    – kdavis8
    Jun 17, 2012 at 1:23
  • \$\begingroup\$ I mean you need a bunch of smaller images that you only load as needed, and use them to assemble the desired picture at screen resulution. Typically these are also present in a hierarchy of prescaled sizes. Another common technique is to construct an infinitely large map on the fly, from a small number of componnets which are designed to fit together. \$\endgroup\$
    – ddyer
    Jun 17, 2012 at 1:47
  • \$\begingroup\$ Most maps for 2D overhead-ish games are built up from tiles, which is basically a bunch of indexes into a texture atlas, which itself is a big bitmap of texture blocks designed to draw next to one another. No one really uses a huge 5k x 5k texture (aka 25 megabytes at only 8bit resolution). That's kind of what he means, with the complication he added of multiple resolutions which you'd only need for scaling from phones to pads, for example. \$\endgroup\$ Jun 17, 2012 at 1:47
  • \$\begingroup\$ thanks your comments sound a lot more effective than what i originally had planned. Quick Question though... should implement these background tiles using Array List or Linked List? \$\endgroup\$
    – kdavis8
    Jun 17, 2012 at 4:55
  • \$\begingroup\$ I'd recommend researching existing 2D tile engines, there are many written in Java and their beacon might keep you from sailing into shallow waters and floundering. You also have to consider an Editor for this map, which is a fair bit of work itself. I assume your goal is to build your own engine instead of actualize a game design? \$\endgroup\$ Jun 17, 2012 at 5:08

You could use an array array to set up the grid for a lot of my code I use a grid class that contains the width and height of the map and i have the tile size. Say the tile size is 50px x 50px then I would set my array array to draw accordingly. for example

Grid<Tiles> map = new Grid(100, 100);

This would set up my grid to hold "Tiles" which would be a different class I had that would have the texture I'd and possibly more info depending on the game I am making. This grid would hold 100 tiles x 100 tiles each 50 pixels making the map 5000px X 5000px.

later when I draw I would have something like this:

for(int r = 0; r < map.getRows(); r++)
    for(int c = 0; c < map.getColumns(); c++)
        draw(map.get(r,c).getTextureID, r*50, c*50) 

This would draw the map at the row and column time the pixels to put it in the right place but if you only want to draw part of the screen it gets a little more complex and you only loop through the rows and columns drawing on your screen.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .