View Full Version : Fog of war effect
flyingmonkey456
June 24th, 2009, 03:09 PM
how do i make a fog of war effect like in starcraft or c&c? it's probably something really simple, lol.
pradvan
June 24th, 2009, 05:05 PM
it's probably something really simple
:stare:
flyingmonkey456
June 24th, 2009, 05:28 PM
:stare:
thanks for your insight :tired:
Gnoll
June 24th, 2009, 05:48 PM
Like fully black outside view? Or somewhat darker but you can still see terrain etc,
You want some kind of mask either way :P
Gnoll
flyingmonkey456
June 24th, 2009, 05:58 PM
Like fully black outside view? Or somewhat darker but you can still see terrain etc,
You want some kind of mask either way :P
Gnoll
i want both, the area you've been in to show terrain and the area you haven't to be completely black. i'm probably going to need 2 masks. i figured out a way, but i don't know how to do it. how do i erase and unerase parts of objects? i know how to make enemies invisible if they're outside of your vision, just do a point test and if they're under the fog make their alpha 0. i know how to make fuzzy edges, just use a glow filter... the only thing i need to know is how to erase parts of an object and bring them back...
Gnoll
June 24th, 2009, 06:08 PM
Using a glow filter for a fuzzy edge effect might be a bit intensive if you have many enemies, if you need to draw lots of stuff I would suggest using blitting.
Good luck,
Gnoll
flyingmonkey456
June 24th, 2009, 06:19 PM
Using a glow filter for a fuzzy edge effect might be a bit intensive if you have many enemies, if you need to draw lots of stuff I would suggest using blitting.
Good luck,
Gnoll
how would enemies cause the glow filter to lag? and how would i use blitting for fuzzy edges?
flyingmonkey456
June 24th, 2009, 09:41 PM
oh, and nobody has told me how to "erase" parts of objects and bring them back >:[
Lou
June 24th, 2009, 10:45 PM
If you're using a tile based engine it should be really simple to cover all your tiles with solid black tiles, and remove them when they are touched by a unit. You could even just set the black tile's alpha to 100 when no units are around, or 0 when something is there. Have the units flag the tile as explored and have the alpha reset to 30 or so, showing explored terrain.
Gnoll
June 24th, 2009, 10:50 PM
I meant blitting for all the graphics, not for making fuzzy edges, and I think the glow filter is somewhat processor intensive (Having heaps of DisplayObjects with it may lower fps considerably).
Gnoll
flyingmonkey456
June 24th, 2009, 10:54 PM
If you're using a tile based engine it should be really simple to cover all your tiles with solid black tiles, and remove them when they are touched by a unit. You could even just set the black tile's alpha to 100 when no units are around, or 0 when something is there. Have the units flag the tile as explored and have the alpha reset to 30 or so, showing explored terrain.
that's a good idea, and yes i am using a tile based engine, but that would make it a little blocky and the glow filter would have to surround every tile which would definitely cause lag. i know there's way to erase parts of objects because it's done in territory war, and there has to be a way to bring them back, too.
flyingmonkey456
June 24th, 2009, 10:58 PM
I meant blitting for all the graphics, not for making fuzzy edges, and I think the glow filter is somewhat processor intensive (Having heaps of DisplayObjects with it may lower fps considerably).
Gnoll
i would only need two objects with the glow filter, the two masks for the fog.
DrRobot
June 25th, 2009, 12:23 AM
what is this effect?
flyingmonkey456
June 25th, 2009, 02:19 AM
what is this effect?
in military strategy games, you know the black fog that covers the battlefield so you can't see anything? that.
flyingmonkey456
June 25th, 2009, 02:38 AM
i figured out how to do what lou was saying without the lag from the fog, if i give a movie clip in a movie clip the glow filter, i think that flattens it. i'm not sure if this would stop the lag though, as some maps would require 250000+ tiles. i think that many tiles all hittesting at once would cause some serious lag... i read online that you can make a mask that shows underneath an object, that's what i need. i'm not sure if that would cause the fuzz effect around the edges though, since it's not actually getting rid of part of the object it wouldn't glow around the edges of the hole. any way to do a mask that makes a gradient hole in an object? that would work great :)
TOdorus
June 25th, 2009, 11:42 AM
I agree with the blitting and tile comments. If you prerender the glowing edges in a tilesheet you don't actually have the overhead for creating the effect. By using tiles you can easily blit the terrain tile with a transparent grey tile on top of it. If it isn't explored you only need to put a black tile in there. I'm 99.9% sure that the old classics you've mentioned did it that way.
flyingmonkey456
June 25th, 2009, 02:21 PM
I agree with the blitting and tile comments. If you prerender the glowing edges in a tilesheet you don't actually have the overhead for creating the effect. By using tiles you can easily blit the terrain tile with a transparent grey tile on top of it. If it isn't explored you only need to put a black tile in there. I'm 99.9% sure that the old classics you've mentioned did it that way.
yes, i know how to make the glow effect flat, but wouldn't 250,000+ tiles all hittesting at once cause lag?
EDIT: actually, the tiles wouldn't be hittesting, i would probably put a circle around every unit and that would be it's sight and that would be pointtesting with every tile. so that's easily 100,000,000 hittests every frame once you get later into the game. any way i can combine every sight circle thing into one object that i can pointtest the tiles with? they have to still be able to move separately, of course.
TOdorus
June 25th, 2009, 04:13 PM
If you're using circular hittests it's actually much simpler. Just check the upperleft position (x-radius, y-radius) and downright position (x+radius, y + radius). Convert these to tile positions and the tiles between these tile coordinates are the tiles it occupies. The easy way is to convert the current position to a tile position and just mark that tile as explored.
Even another way is to get the tile position of the centre position and check the x's and y's of the lines surrounding the tile. Let's say you're on coordinate (3,1) with tilewidth and height 30. This would mean the left line is x = 3*30 and the right line is x = (3+1)*30. Same for y (up: y = 1*30 down is (1+1)*30. Check the position +- radius against these lines.
var tileX:int //=3
var tileY:int //=1
//Left
if(this.x - this.radius < tileX*tileWidth){
occupying left tile
}
if(this.x + this.radius > (tileX+1)*tileWidth){
occupying right tile
}
if(this.y - this.radius < tileX*tileHeight){
occupying up tile
}
and so on
if it occupies the up and right tile it will also occupy the upright tile etc.
This may sound expensive, but this is relatively cheap. I've done way much more AI and collision detections and AI routines in a frame. The real expense in flash is the display (drawing to the screen). Movieclips are quite expensive. I suggest you read up on blitting using copypixels to make a rts with a decent framerate feasable. You basicly copypixel everything to a single bitmapdata which is assigned to your only bitmap onscreen. This way Flash only updates one object (the bitmap) which saves a lot. Give me a pm if you need some help on that, as that's quite the subject on it's own. I've written about it in another thread (http://www.kirupa.com/forum/showthread.php?t=324447)though.
flyingmonkey456
June 25th, 2009, 04:27 PM
tod, do you know how to make part of an object invisible? that's what i've been asking this whole time, lol. if i do that, i just make 2 black masks, one with 100 alpha and one with 50 or so. the unit sights would permanently erase the 100 alpha mask, and only erase the part of the 50 alpha mask that they can see. that would actually be pretty simple and wouldn't cause much lag.
therobot
June 25th, 2009, 07:56 PM
Use blitting & only plop down the tiles that are visible. You shouldn't need a mask. You shouldn't need to draw 1000s of tiles - just whatever should be visible on-screen.
Copy the background tiles to your canvas, copy the sprites to your canvas, and then copy black tiles over things that haven't been explored yet. If a sprite is half-on an explored tile and half-on an unexplored tile, you will achieve your same masking effect when the black tile gets pasted over your sprites.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.