Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / fog of war tile transitions. help please - I have code and demo

Author
Message
Lost Dragon
15
Years of Service
User Offline
Joined: 22nd Aug 2010
Location:
Posted: 15th Feb 2012 08:36
I'm back. Ready your faces for palming.

I'm still programming a little 2D tile engine ala the old retro RPGs of yore (Ultima, Wasteland, etc.)

I've programmed a fog of war setup that uses a rogue-like line of sight routine to determine which blocks are "seen" and then it does post-processing on darkened tiles to make the edges rounded off.

It works okay when the player is outdoors. I never could get it to work indoors and I couldn't understand why.

My question for now is - is there an easier way to do this? My method was the most straightforward answer I could come up with. I go to each dark tile on the viewport, see what tiles are around it, and then I paste a pre-made curved or otherwise "fitted" tile to make the transition smooth.

Here's part of the code that does the tile transitions outside.

All tiles start covered in darkness/fog of war.

If a tile is "discovered" then it has been seen by the player and will always show up - unless the player goes in a building. Walls always block line of sight.

.dark = 42, .dark = 44, etc. Those are my transition tile graphics. I have one for each cardinal compass direction.

As I mentioned above the routine checks to see what neighbor tiles are doing and then determines what tile to place to make it smooth looking. It also eliminates shapes that I don't have graphics to cover - like long 1 tile wide rows.

A "roof" tile is really just a floor tile. I'm using "roof" to indicate that it's a tile that is considered "inside". I will rename that later.



I also attached a WIP so you can see it in action.

Please let me know if there is a better way to do this. I suspect there is but I could not understand the few examples I saw online.

I'm sort of curious as to what FPS you are getting too.
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 15th Feb 2012 12:41 Edited at: 15th Feb 2012 12:45
You could make it very smooth with faded alpha tiles, and a black, or foggy background. Just alter the fade setting in a linear fashion, and an amazing fog effect.

Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 15th Feb 2012 16:48
I recently made some transition handling code, but I'm not sure how relevant it is to you.

What I did, was gave each corner a binary bit, so 4 bit, top left is bit 1, top right bit 2, bottom right bit 3 - etc etc. Then, if there is a matching block at each corner, the bit is set, and that generates a number from 0 to 15, uniquely identifying the tile. I did this for grass to sand style transitions, but there's no reason why it wouldn't work for this as well. I don't actually use binary, I just gave each corner a sensible value:

top left = 1
top right = 2
bottom right = 4
bottom left = 8

Then imagine the top left and bottom right tiles are filled, that means top left and bottom right, or 1 + 4, so tile 5. My plan is to have various texture transitions, but using the same strict system - so I'd have grass to sand transitions, and sand to wet sand, sand to rock, grass to dirt etc etc - all squeezing onto a single 16x16 tile sheet.

I have it generate the tile sheet using the box command with coloured vertices, and it is quite efficient at setting the tiles to suit. It samples the corners, and works out the tile to use at that location. It kinda favors filling in tiles if you know what I mean though - like it'll surround matching tiles, rather than replace them, so a single tile would be left alone, and transition tiles added all around it. It might still be fine for fog of war, depending on how you flag visible tiles.

Anyway, I'd be happy to post more details and some example code if you think it would help.


One other option, is to make a fairly low res image, say the same resolution as your map, stretch it over the whole map, then draw onto the image to represent the fog map. If you use negative ghosting, paint in white on a black backdrop, then it would provide a pretty efficient fog of war layer. I've been messing around with the awesome ImageKit, and it allows this sort of thing quite easily - I am using a similar technique for a light map, each loop I paste a low alpha black image then white light images. This is textured onto a negative ghosted plain, so I have full control over lighting, it fades to black, and it'll allow for some pretty neat lighting effects. You could even be lazy, and do something similar to what I am, then instead of managing the visibility, just paste the low alpha black image to fade it, then paste a smooth dot wherever you paste visible tile - that way you would move away from areas, and they'd fade out smoothly.

Health, Ammo, and bacon and eggs!
Lost Dragon
15
Years of Service
User Offline
Joined: 22nd Aug 2010
Location:
Posted: 16th Feb 2012 19:11
Van B I am interested in hearing more about your tile transitioning code ideas.

In addition to smoothing out the darkness tiles it would also be nice not to have to draw in all the coastline curves by hand in the tile editor as I do now.
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 17th Feb 2012 10:24
No worries, I'll make a little example of this method tonight.

Health, Ammo, and bacon and eggs!

Login to post a reply

Server time is: 2026-07-10 01:31:11
Your offset time is: 2026-07-10 01:31:11