Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


[java] Tilebased maps.

This topic is 6218 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I have read every bit of information I can find online about creating scrolling tile-based world maps in java. I''m ready to knock together a map, but really don''t know if there''s a method I should be using to actually draw the images. I have numerous multi-layer images ( as described by Greg Taylor in his "TileBased Games FAQ" ) to use for tiles and actors. But, I want to make sure that I draw them to my graphics object in the most effecient way. Baring in mind that my map will be over 10000 pixels wide and 4000 pixels high, can anyone help me with a few snippets of code to actually drawr the images in the most effecient way. I really don''t know whether I need to plot individual pixels from one massive world image buffer, or whether I plot each tile seperately with a quick drawImage. Thanks in advance for ANY help here guys ... Tobe

Share this post

Link to post
Share on other sites

In order to be sure that your drawing is as fast as possible you have to fist convert all of your images to screen native format. ( From here on out I''m assuming you have Java2 ( 1.2, 1.3, 1.4 ) with Java2d installed ).

The easiest way it to use first make an offscreen image with

BufferedImage offscreen = GraphicsConfiguration.createCompatibleImage(Width,Height);

You then will want to do all of your drawing into that offscreen image. Your opaque tilesets should also be copied to BufferedImages created with that same snippet.

For sprites and other masqued images you should copy them to BufferedImage created like so.

BufferedImage someimage = GraphicsConfiguration.createCompatibleImage(Width,Height,Transparency.BITMASK);

and for translucent sprites/tilemaps

BufferedImage someimage2 = GraphicsConfiguration.createCompatibleImage(Width,Height,Transparency.TRANSLUCENT);

This will be the best possible 100% pure solution to make sure that drawImage(...) will be as fast as possible. You should do some testing to see if individual 1 BufferdImage per tile/sprite frame is faster than a bulk image as the Graphics2D only support a drawImage(image,null,x,y);

Hope this get you going in the right direction. There is also the neat ability to do run lenght sprite encoding and a custom blitter that might speed this up even more. If you need per pixel writing ability ( gfx/effects/whatever ) I can show you how to apply them directly to the backbuffer using array accesses.

Good luck

Share this post

Link to post
Share on other sites
The key thing for you is probably to make sure you don''t try to draw all of the images (seeing as I guess you don''t have a monitor that can do 10000x4000 pixels!). One good way would be to break up the map into "areas", each area, say containing roughly 1/4 of what you will display on screen. That way you can check whether each area lies on screen, before you decide to draw it''s contents. If you wan''t an even more efficient way of doing things, you might want to look at quad-trees.
The next thing to remember is that when the user is not moving around the map, you don''t need to constantly redraw the background, I suggest looking into "dirty rectangles" for ways of doing that.


Little Spikey Land

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!