A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: a/s level fade transition source

  1. #1
    Senior Member mbenney's Avatar
    Join Date
    Mar 2001
    Posts
    2,744

    a/s level fade transition source

    i wrote this today, its simple but pretty cool and works well... im using it as level transition. screen fades to black, call back is called to draw the new level before it fades back to clear.

    just thought someone might like it =)

    code:

    /* --- params ---
    xPos/yPos - top left hand corner position
    width/height - rectangle sizes
    rate - speed at which the fade goes
    colour - colour of rectangle
    dep - depth to attach clip
    callbac - function to call when the rectangle is mid-fade
    --- ----- --- */

    function fadeOut(xPos, yPos, width, height, rate, colour, dep, callbac) {
    var a = 12;
    pane = createEmptyMovieClip("pane", dep);
    pane._x = xPos;
    pane._y = yPos;
    pane.onEnterFrame = function() {
    if (a>=120) {
    rate = -rate;
    callbac();
    }
    drawPane(width, height, a += rate, colour);
    if (a<0) {
    pane.removeMovieClip();
    delete this.onEnterFrame;
    }
    };
    }
    function drawPane(width, height, alpha, colour) {
    with (pane) {
    clear();
    beginFill(colour, alpha);
    lineTo(width, 0);
    lineTo(width, height);
    lineTo(0, height);
    lineTo(0, 0);
    endFill();
    }
    }



    usage example...
    code:
    fadeOut(20, 25, 360, 250, 4, 0x000000, 1, build);



    [m]

  2. #2
    SaphuA SaphuA's Avatar
    Join Date
    Oct 2002
    Location
    The Netherlands
    Posts
    2,182

    :)

    Hehe...

    That's pretty funny

  3. #3

  4. #4
    A very senior man mrpauly99's Avatar
    Join Date
    Feb 2002
    Location
    Cool Britania
    Posts
    429
    am i the only one thats too lazy to open flash and try out the code? i love it when you get links to try out

  5. #5
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    Sweet as ever [m]

    Squize.

  6. #6
    avatar free
    Join Date
    Jul 2002
    Location
    UK
    Posts
    835
    Sweet. Just one thing i'm unsure about (been away from flash for 2 months for exams, so forgive me if it's just my memory) but if you remove the movie clip "pane" how can you delete it's onEnterFrame. Does the oEF still exist, even though the clip hass gone?

    Code:
    pane.removeMovieClip();
    delete this.onEnterFrame;
    T'other way round? Or is it not necessary for delete at all?

    Sweet though
    jonmack
    flash racer blog - advanced arcade racer development blog

  7. #7
    Senior Member mbenney's Avatar
    Join Date
    Mar 2001
    Posts
    2,744
    silly me, everyone can take that line out =)

  8. #8
    Untitled-2.fla
    Join Date
    Jul 2002
    Posts
    391
    pretty neat, you can save a few fps if you only draw the pane once - right after creating the movie clip and just use the enterFrame loop to alter the alpha

  9. #9
    Senior Member mbenney's Avatar
    Join Date
    Mar 2001
    Posts
    2,744
    good call, i dont mind if someone optimises it!

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