scrolling tiled map

for my final project im thinking of making a 2d tiled map game. i plan to have this map scrollable becuase the game map will be very large.

Do you guys think putting this map on a JPanel and then putting it into a JScrollPane would make this map scoll fast enough?

Also with this map is it nessary to use a buffer?

That depends on what kind of game you’ll make. If it’s a strategy game with not that much animations and scrollings going on for example, then I see no problems in using Swing. See JFreeRails for an example of this:

http://freerails.sourceforge.net/
http://freerails.sourceforge.net/jfreerails.jnlp

But if you are planning to make a fast paced action game with lots of scrolling and animations going on you’d be better of using BufferStrategy to draw the tiles onto the screen.

A simple sollution would be to create an int matrix which symbolizes the tiled map, an array of BufferedImages that the matrix int links to and a x and y int that tells which matrix position currently should be painted to the upper left corner of the game window.

anything that involves stuff moving around onscreen while the scrolling is happening will not be too smooth… for something where the scrolling is just a means of looking at another area and most of the action takes place with the view point still, this sort of thing is not too bad, but bufferStrategy is really the better option inthe long run.

thx for the replies, so far i’ve made an array of images taht will be drawn onto a buffer then its copied to a jPanel which is on a JScrollPane and when i scroll its reallllllly sloooow…

this map is simiar to civilization, there arent any animation at all just images of terrain. i dont understand why its so sloww

is there sth that im doing wrong?

I really don’t have any experience of using a JPanel and JScrollPane for games so I can’t give you hints on that. But JFreeRails does it succesfully and the source is available, so you could take a look on that source and find out how it is done there.