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.
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.
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]