Results 1 to 7 of 7

Thread: "Fog of war" test. Help me out.

  1. #1

    "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


    Code:
    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?

  2. #2
    Beautiful.

    I didn't get exactly what's the problem with it. (Besides the fact it's not attached to the mouse)
    Bruno Palermo
    When everything is catastrophic, thank the Gods things aren't worse!

  3. #3
    1,532
    posts
    I make half sense
    very nice!

    I don't quiet get what the error you have is, as with the person above.
    Click my sig.

  4. #4
    Quote Originally Posted by bpalermo View Post
    Beautiful.

    I didn't get exactly what's the problem with it. (Besides the fact it's not attached to the mouse)
    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

  5. #5
    207
    posts
    Registered User
    I've done this exact same mistake before:
    ActionScript Code:
    var HexT:Object = {x:FOW[k]._x, y:FOW[k]._y, MC:FOW[k]};
    FOW[k].localToGlobal(HexT);


    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:
    var HexT:Object = {x:0, y:0, MC:FOW[k]};

  6. #6
    Quote Originally Posted by rrh View Post
    I've done this exact same mistake before:
    ActionScript Code:
    var HexT:Object = {x:FOW[k]._x, y:FOW[k]._y, MC:FOW[k]};
    FOW[k].localToGlobal(HexT);


    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:
    var HexT:Object = {x:0, y:0, MC:FOW[k]};

    THANK YOU.

  7. Reported.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012