"Fog of war" test. Help me out

I’m trying to make simple Fog of war(if you aren’t near it, you can’t see it sort of thing) for a game I’m making.
It sort of works, but it’s a bit off.

http://img216.imageshack.us/my.php?image =fowtestdn3.swf

function FieldOfView() {
	for (k in _root.FOW) {
		//loop through all MC's within "FOW"
		var HexT:Object = {x:FOW[k]._x, y:FOW[k]._y, MC:FOW[k]};
		//make a "HexT"(Hex tile) object
		FOW[k].localToGlobal(HexT);
		//localToGlobal it's values
		XX = HexT.x-_xmouse;
		YY = HexT.y-_ymouse;
		Distance = Math.round(Math.sqrt((XX*XX)+(YY*YY)));
		//calculate distance
		HexT.MC._alpha = Distance/2;
		//set alpha
	}
}
onEnterFrame = function () {
	FieldOfView();
};

It’s probably has to do with the localToGlobal, but if I disable it the shift is worst. Oh, and setting it to “HexT.MC._alpha = Distance” instead of “HexT.MC._alpha = Distance/2” also isn’t it. the /2 just give it a bigger…range let say.

What do you think? :hat:

Beautiful.

I didn’t get exactly what’s the problem with it. (Besides the fact it’s not attached to the mouse)

very nice!

I don’t quiet get what the error you have is, as with the person above.

[quote=bpalermo;2341385]Beautiful.

I didn’t get exactly what’s the problem with it. (Besides the fact it’s not attached to the mouse)[/quote]

That’s exactly the problem I’m having. It’s not centered around the mouse and I don’t know why.

I was thinking of just hitTesting everything, but that wouldn’t look as nice nor would it give me the functionality I want…

Ideas?

Ps. thanks for the compliments :hugegrin:

I’ve done this exact same mistake before:
ActionScript Code:
[LEFT][COLOR=#000000]var[/COLOR] HexT:[COLOR=#0000FF]Object[/COLOR] = [COLOR=#000000]{[/COLOR]x:FOW[COLOR=#000000][[/COLOR]k[COLOR=#000000]][/COLOR].[COLOR=#0000FF]_x[/COLOR], y:FOW[COLOR=#000000][[/COLOR]k[COLOR=#000000]][/COLOR].[COLOR=#0000FF]_y[/COLOR], MC:FOW[COLOR=#000000][[/COLOR]k[COLOR=#000000]][/COLOR][COLOR=#000000]}[/COLOR];
FOW[COLOR=#000000][[/COLOR]k[COLOR=#000000]][/COLOR].[COLOR=#0000FF]localToGlobal[/COLOR]COLOR=#000000[/COLOR];
[/LEFT]

Consider, what does that x and y represent? The position of FOW[k] within the context of its parent. What does the localToGlobal do? Translates from the context of FOW[k] to a global context. You are treating FOW[k] as if it is contained within itself.

This should be better:
ActionScript Code:
[LEFT][COLOR=#000000]var[/COLOR] HexT:[COLOR=#0000FF]Object[/COLOR] = [COLOR=#000000]{[/COLOR]x:[COLOR=#000080]0[/COLOR], y:[COLOR=#000080]0[/COLOR], MC:FOW[COLOR=#000000][[/COLOR]k[COLOR=#000000]][/COLOR][COLOR=#000000]}[/COLOR];
[/LEFT]

[quote=rrh;2341509]I’ve done this exact same mistake before:
ActionScript Code:
[LEFT][COLOR=#000000]var[/COLOR] HexT:[COLOR=#0000ff]Object[/COLOR] = [COLOR=#000000]{[/COLOR]x:FOW[COLOR=#000000][[/COLOR]k[COLOR=#000000]][/COLOR].[COLOR=#0000ff]_x[/COLOR], y:FOW[COLOR=#000000][[/COLOR]k[COLOR=#000000]][/COLOR].[COLOR=#0000ff]_y[/COLOR], MC:FOW[COLOR=#000000][[/COLOR]k[COLOR=#000000]][/COLOR][COLOR=#000000]}[/COLOR];
FOW[COLOR=#000000][[/COLOR]k[COLOR=#000000]][/COLOR].[COLOR=#0000ff]localToGlobal[/COLOR]COLOR=#000000[/COLOR];
[/LEFT]

Consider, what does that x and y represent? The position of FOW[k] within the context of its parent. What does the localToGlobal do? Translates from the context of FOW[k] to a global context. You are treating FOW[k] as if it is contained within itself.

This should be better:
ActionScript Code:
[LEFT][COLOR=#000000]var[/COLOR] HexT:[COLOR=#0000ff]Object[/COLOR] = [COLOR=#000000]{[/COLOR]x:[COLOR=#000080]0[/COLOR], y:[COLOR=#000080]0[/COLOR], MC:FOW[COLOR=#000000][[/COLOR]k[COLOR=#000000]][/COLOR][COLOR=#000000]}[/COLOR];
[/LEFT]
[/quote]

THANK YOU. :smiley:

Reported.