A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Distance from boundry

  1. #1
    Senior Member
    Join Date
    Apr 2001
    Posts
    996

    Distance from boundry

    I have a clip that needs to fade out, as it gets closer to a boundary.
    I have the boundaries set in and object called __bounds
    Code:
    	public function setBounds(b) {
    		__bounds.top = b.yMin;
    		__bounds.bottom = b.yMax;
    		__bounds.left = b.xMin;
    		__bounds.right = b.xMax;
    	}
    I also have a mc traveling at a specific velocity
    Each clip has a random velocity

    Code:
    _x+=__vx
    _y+=__vy
    What I’m trying to do is create a function in my class to figure out
    If my clip is within a 20-30-pixel distance of its boundary then fade out according to the speed it is coming towards the boundary.

    I set up a function to fade if it was within 30 pixels of its boundary but the problem was to fade it according to the speed it is coming towards the boundary so it has totally faded out as it hits its boundary.

    Can anyone explain how to do this?

    Thanks

  2. #2
    Opu Nui
    Join Date
    Jan 2003
    Location
    I'd rather be in Hawaii
    Posts
    79
    This code will change the alpha property of an object according to its distance from a boundary. At the beginning it will have 100% alpha and 0% at the end. The faster it goes through this section the faster it will change.

    MX is the maximum x value
    FS is the fade start x value

    Code:
    this.alpha=(-100/(MX-FS))*this._x+(MX/(MX-FS))*100;
    I hope this helps.

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center