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.
setVirtualResolution(800,600)
#CONSTANT MAP_WIDTH = 100
#CONSTANT MAP_HEIGHT = 80
#CONSTANT FOG_ON = 1
#CONSTANT FOG_OFF = 2
Type Tile
frame as integer
fog as integer
EndType
base = createSprite(loadImage("tiles.png"))
setSpriteAnimation(base, 48, 48, 15)
fog_base = createSprite(loadImage("fog.png"))
setSpriteAnimation(fog_base, 48, 48, 2)
dim tiles[MAP_WIDTH, MAP_HEIGHT] as Tile
tileSize as float
tileSize = 48
Global _ViewWidth
Global _ViewHeight
_ViewWidth = ceil(getVirtualWidth() / tileSize) + 1
_ViewHeight = ceil(getVirtualHeight() / tileSize) + 1
dim viewport[_ViewWidth, _ViewHeight] as Tile
for x = 0 to MAP_WIDTH
for y = 0 to MAP_HEIGHT
tiles[x,y].frame = random(1,15)
tiles[x,y].fog = FOG_ON
next y
next x
for x = 0 to _ViewWidth-1
for y = 0 to _ViewHeight-1
viewport[x,y].frame = cloneSprite(base)
setSpritePosition(viewport[x,y].frame, x*tileSize, y*tileSize)
setSpriteFrame(viewport[x,y].frame, tiles[x,y].frame)
viewport[x,y].fog = cloneSprite(fog_base)
setSpritePosition(viewport[x,y].fog, x*tileSize, y*tileSize)
setSpriteFrame(viewport[x,y].fog, tiles[x,y].fog)
next y
next x
setSpriteVisible(base, 0)
setSpriteVisible(fog_base, 0)
// map offset
OX = 0
OY = 0
// map scroll speed
speed = 4
// demo purposes
oldMx = getRawMouseX()
oldMy = getRawMouseY()
do
mx = getRawMouseX()
my = getRawMouseY()
if oldMx <> mx or oldMy <> my
fx = trunc((getRawMouseX() + OX) / tileSize)
fy = trunc((getRawMouseY() + OY) / tileSize)
oldMx = mx
oldMy = my
setMapFog(fx, fy, FOG_OFF)
endif
moveViewport = 0
// right
if getRawKeyPressed(39) = 1
inc OX, speed
`if OX > ? then OX = ?
moveViewport = 1
endif
// down
if getRawKeyPressed(40) = 1
inc OY, speed
`if OY > ? then OY = ?
moveViewport = 1
endif
// left
if getRawKeyPressed(37) = 1
dec OX, speed
if OX < 0 then OX = 0
moveViewport = 1
endif
// up
if getRawKeyPressed(38) = 1
dec OY, speed
if OY < 0 then OY = 0
moveViewport = 1
endif
if moveViewport = 1
for x = 0 to _ViewWidth-1
for y = 0 to _ViewHeight-1
ix = x*tileSize - OX
iy = y*tileSize - OY
setSpritePosition(viewport[x,y].frame, ix, iy)
setSpritePosition(viewport[x,y].fog, ix, iy)
next y
next x
endif
print(fx)
print(fy)
Sync()
loop
function setMapFog(x, y, state)
tiles[x,y].fog = state
if x < _ViewWidth and y < _ViewHeight then setSpriteFrame(viewport[x,y].fog, state)
endfunction
"I like offending people, because I think people who get offended should be offended." - Linus Torvalds