Map question

Using a tile map, basically I have each tile being drawn out from the individual tile images each frame. Is there some way I create a new image for the entire background (the map background) made up of the tiles so that next time I can just draw the map shifted instead of re-creating the map?

you could save it to a BufferedImage. it would be a huge memory killer though. drawing tiles over and over isnt really that big of a deal…

Hm. Well the problem I’m having is that when you run to the left or right it scrolls the screen with you. But it’s basically building the tiles on the end, so the edge of the screen you’re running towards flashes black then back to what to the map. I fixed it on the right and bottom edges by building 1 tile past your view, but I can’t figure out how to build in the left and upper directions past the screen (since it doesn’t seem to wanna draw at -50,-50). Any idea how to do this so it doesn’t flash?

sounds like a problem with my tile map engine. My problem is that at lower framerates, u can see a quick flash of black, because the tiles on that edge werent rendered. but the weird thing is that i thought i was rendering 1 tile ahead. But if i render another tile ahead ill get array out of bound error and it annoying. it also wont render tiles that are past the upper and left edges(0,0), because the array pos(-1,-1) doesnt exist, id like to render on upper left and lower bottom right one extra tile that is blank, so my new interfaces wont block those tiles.

@TLE
Look how this is solved in that scrolling example I gave you? I didn’t see any flickering on edges there.
I have a very lame idea, draw everything starting at 50,50 and then draw left and upper extra tiles. Then translate everything back for -50, -50. Even if this works I’m pretty sure this isn’t how it’s done :slight_smile:

I looked at that example but I couldn’t follow it at all. I tried the -50,-50 thing, actually did -250,-250 even though my tiles are 50x50. Problem is even if you can make the image go past (0,0) (negatively), you cannot draw to the full screen past 0,0. So I can only begin the picture as far back as 0,0 and draw in the positive direction from there. I’ll try looking through that example some more later. Is there anybody out there who’s done this before and knows what to do?

Well, I’m using an offset to scroll, so my other idea was to draw partial tiles on the edges, but you have to be using buffered images for that and graphics2D too I think – I haven’t had gotten my code changed to those (and operating) yet. Maybe that’ll work.

Just got the buffered image set up and got the edges to work with using partial tiles of the next tile, and it worked like I expected in the sense that it stopped the bluring and chopping at the edges, but when moving at moderate speeds it REALLY makes the map screwed up looking.

what do you mean screwed up looking? What is wrong now?

The tiles sort of mix into each other, so it looks really screwy. Not sure what the problem is. I figured out what was going on in that scrolling example, they’re doing the same thing I did it looks like, but they’re using fillRect instead of drawing gif images, so the example doesn’t have anything complicated enough as what I’m trying to do.

Anybody know how to do this scrolling with a tile map or know any other examples I can look at?

you can look at my example:
http://www.java-gaming.org/forums/index.php?topic=15548.0

but its waaay out of date. i already fixed those problems, besides some minor ones. and im using new textures that are bigger and better.

fillRect and drawImage, as we are concerned here, do the same thing… they draw a rectangle on some graphics object. So If I were you I would study that example more closely. Try to edit it and instead of fillRect draw an image with same dimensions.

That’s what I did Kova, it looks fine when I use fillRect. Looking through DarkMortar’s example now, going to take some time

Here is a link to the newest version. Sorry for some miss-comments within the code, and some sloppiness. But this is my noob attempt at what I’ve done. But it works in ways I think you want, it has visiblity controls that work, and its fast, and it draws 16-bit .png images that are 100x100.

Ignore my silly textures, some of them are still 80x80, so those dont draw right, but I think this will help you out. Look at this version of my tilemap.

Right now im working on a hexidecial version, that I will use for my turn-based strategy im planning.

http://storeandserve.com/download/707657/WorldGenerator2.0.rar.html