Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

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