tags:

views:

1238

answers:

2
+6  A: 
    for (x=0; x<= width / tileWidth; x++)
    {
            for (y=0; y<= height / tileHeight ; y++)
            {
                    g.drawImage(tile, x * tileWidth, y * tileHeight, this);
            }
    }

You need to offset by the width/height of the tile.

FlySwat
It looks better but not quite right.. http://i41.tinypic.com/27y4d4x.jpg. I want every tile to be distinguishable from the other..
Click Upvote
Great, i increased the tile.png file size to 25x25 and created a border around it and it looks exactly how i'd wanted now. thanks!
Click Upvote
+3  A: 

Just as a side note, you are probably going to want to start checking your "Clip Region" at some point and not drawing stuff outside that region. Your code is set up pretty well to do that.

The other thing you could do to speed it up is "Double Buffer". Create a component the size of your map, call getGraphics() for that component, do all your drawing to this new graphics object, then just draw your component to the real Graphics object passed into your paint method.

A nice thing about this is that you can draw your entire map before you ever hit the paint statement, then slap it out instantly.

Google Double Buffering in Java for more info.

Bill K