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.

Newcomers AppGameKit Corner / fog of war type effect in 2d map

Author
Message
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 2nd Sep 2016 20:38 Edited at: 2nd Sep 2016 21:45
i'm trying to create a 2d game with a fog effect that will cover the screen until explored.
currently i just use lots of small sprites (think grid on the screen) and remove them as needed which works fine but it really slows down performance a lot (i want to use a lot of sprites / have small shapes removed at a time)
so is there a better way to achieve this result?
something like setting parts of an image/sprite transparent only?
the fog can be removed from any spot at any time really.

edit;
been playing around with setimagemask but i cant quite get it to work correctly, how do the offsets work? mine seem to be 0 ~ 31 in width and 0 ~ 25 in height for the whole screen?
how do i adjust the size of the image used too? currently i'm adjusting the actual .png file to make the change.
this is what i've got so far

life\'s one big game
spec= 2.6ghz, 1gb ram, 512mb gpu, directx 9.0c, dbpro and classic
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 3rd Sep 2016 01:57 Edited at: 3rd Sep 2016 03:08
If your map is set up tile-based, I'd have a second layer on top that lies inline with the surface map. This will be the fog map. And just as you would update the onscreen tiles for your map when you scroll, you could do the same affect to the fog layer. It just all kinda depends on the resolution of the fog you want.

Here's a real basic idea and I kinda half-arsed the tilemap scrolling, but you get the idea.


"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Attachments

Login to view attachments
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 3rd Sep 2016 12:22
thanks and yh that was my first method but after about 200 sprites my phone gets slower and slower so i wanted a quicker method.
the image mask is what i needed (i can now very quickly and without loss get the same effect as having thousands of sprites as fog) i just didn't understand the offsets but i got it now, they're based on the original image used (pixel size) but as i was trying to use a sprite as the original image i forgot i should be looking at the image used for the sprite and not the sprite itself and also because the sprite wasnt originally at 0,0 it didn't translate correctly in my head that 0,0 was not where the sprite origin was but the top left of the screen.
so if your image is 32x32 then you need to use 0,0 for the top left, 16,16 for the middle etc... the image size of the 2nd image adjusts how much of the image is covered, i.e. using a 1x1 image at 0,0 will cover a small part of the top left, while using a 32x32 image at 0,0 will cover the entire image with the new one.
life\'s one big game
spec= 2.6ghz, 1gb ram, 512mb gpu, directx 9.0c, dbpro and classic
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 5th Sep 2016 13:18
You should make an example of your solution. I'm sure others would be interested in a FOW demo.

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Mark532011
7
Years of Service
User Offline
Joined: 27th Jun 2016
Playing: X-Com, WOW-Legion
Posted: 13th Sep 2016 23:27
Couldn't you do something like set the opacity to zero if more than a specific distance away in the x,y,z direction? Seems like that would be pretty fast but I don't know for hundreds of sprites.

Login to post a reply

Server time is: 2024-04-19 05:43:20
Your offset time is: 2024-04-19 05:43:20