# "Fog of war" test. Help me out

**URL:** <https://forum.kirupa.com/t/fog-of-war-test-help-me-out/263020>\
**Category:** Uncategorized\
**Created:** [June 11, 2008, 10:57pm UTC](https://forum.kirupa.com/t/fog-of-war-test-help-me-out/263020 "2008-06-11T22:57:07Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![zuperxtreme](https://avatars.discourse-cdn.com/v4/letter/z/e9a140/32.png) [@zuperxtreme](https://forum.kirupa.com/u/zuperxtreme)\
**Post date:** [June 11, 2008, 10:57pm UTC](https://forum.kirupa.com/t/fog-of-war-test-help-me-out/263020/1 "2008-06-11T22:57:07Z")

</div>

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](http://img216.imageshack.us/my.php?image=fowtestdn3.swf)

```auto
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:

---

<div class="post-metadata">

**Author:** ![bpalermo](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@bpalermo](https://forum.kirupa.com/u/bpalermo)\
**Post date:** [June 12, 2008, 2:10pm UTC](https://forum.kirupa.com/t/fog-of-war-test-help-me-out/263020/2 "2008-06-12T14:10:47Z")

</div>

Beautiful.

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

---

<div class="post-metadata">

**Author:** ![randomagain](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@randomagain](https://forum.kirupa.com/u/randomagain)\
**Post date:** [June 12, 2008, 2:44pm UTC](https://forum.kirupa.com/t/fog-of-war-test-help-me-out/263020/3 "2008-06-12T14:44:42Z")

</div>

very nice!

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

---

<div class="post-metadata">

**Author:** ![zuperxtreme](https://avatars.discourse-cdn.com/v4/letter/z/e9a140/32.png) [@zuperxtreme](https://forum.kirupa.com/u/zuperxtreme)\
**Post date:** [June 12, 2008, 3:52pm UTC](https://forum.kirupa.com/t/fog-of-war-test-help-me-out/263020/4 "2008-06-12T15:52:24Z")

</div>

[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:

---

<div class="post-metadata">

**Author:** ![rrh](https://avatars.discourse-cdn.com/v4/letter/r/67e7ee/32.png) [@rrh](https://forum.kirupa.com/u/rrh)\
**Post date:** [June 12, 2008, 4:19pm UTC](https://forum.kirupa.com/t/fog-of-war-test-help-me-out/263020/5 "2008-06-12T16:19:46Z")

</div>

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]

---

<div class="post-metadata">

**Author:** ![zuperxtreme](https://avatars.discourse-cdn.com/v4/letter/z/e9a140/32.png) [@zuperxtreme](https://forum.kirupa.com/u/zuperxtreme)\
**Post date:** [June 12, 2008, 4:27pm UTC](https://forum.kirupa.com/t/fog-of-war-test-help-me-out/263020/6 "2008-06-12T16:27:31Z")

</div>

[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. 😃

---

<div class="post-metadata">

**Author:** ![ArmoredSandwich](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@ArmoredSandwich](https://forum.kirupa.com/u/ArmoredSandwich)\
**Post date:** [June 19, 2008, 11:03am UTC](https://forum.kirupa.com/t/fog-of-war-test-help-me-out/263020/7 "2008-06-19T11:03:59Z")

</div>

> [@wowgold2008;2345472](#):
>
> [SIZE=2][wow gold[URL=“http://www.tgacn.com/cd-key.htm”]lineage2 cd key[URL=“http://www.tgacn.com/cd-key.htm”]age of conan gold[URL=“http://www.tgacn.com/aoc-gold.html”]aoc gold[URL=“http://www.tgacn.com/cd-key.htm”]world of warcraft cd key](http://www.tgacn.com/wow-gold.htm)wow gold[/SIZE]

Reported.
