Java game with tiled map background problem
I am trying to develop a Java 2D game and I have a problem with the tiled background. I am using the book Developing Games In Java as a tutorial but this part is insufficient so I need your help. The game map is based on a array
String fileName[]
{
"wwwwwwwwwwww",
"pppppppppppp",
"oooooooooooo"
};
I try to place this array on a JFrame. After us开发者_C百科ing a double for loop in order to read it and fill a specific image for each letter, I can see that no image is displayed. Is the way of thinking that I use correct or requires more? Please help
The main issue I see is that you are drawing your images at 1-pixel increments. You should probably be multiplying i and j by the width and height of a tile, respectively.
Additionally, you are loading your images once to cache them (in loadImages()
), and then again on every single loop iteration. Very slow, and pointless.
Problem solved. There was an error array out of bounds due to the fact that the the array width was 4 and the height was 3.
精彩评论