Bubbles Floating Upward?
A Flash Developer Resource Site

Results 1 to 18 of 18

Thread: Bubbles Floating Upward?

  1. #1
    Senior Member
    Join Date
    May 2003
    Posts
    160

    Bubbles Floating Upward?

    I would like to create a banner for my site that has little hearts floating upward. I would like them to have a random _y start position, random size, and sway on a sine wave curve. It would be great if I could define the max amount of hearts to be on stage at once or have a timer that defines how often a heart gets spawned. Can someone please help me out? THANKS!

  2. #2
    Member
    Join Date
    Oct 2003
    Location
    Colorado Springs
    Posts
    82
    look at duplicating movie clips.
    for max ammount on stage set parameters for y, so if the mc goes off the top of the swf screen then it would remove itself from the swiff. When you create a new duplicate, increase the count number. But before you duplicate a clip make sure the number you have been incrementing is not greater than the max ammount. Make sure to decrease the incrementing variable when you remove a movie clip.

    I havn't done much with sin or cos but if you create a movie clip that sets its y to random number in onClipEvent(load) then when you duplicate a movieclip, it will inherit those properties and move according to however you specify.
    Justin Blough
    MindWireMedia
    (719) 659-8062
    justin.blough@mindwiremedia.net
    http://www.mindwiremedia.net

  3. #3
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    See attached fla.

    This is the script. It assumes there is an exported movieclip in the library called 'hearts' that contains 3 frames, each with a picture of a different style heart.

    code:

    kNbrHearts = 60; // number of hearts
    kNbrPix = 3; // number of heart pix
    kMinSpeed = 1; // minimum rise speed
    kMaxSpeed = 20; // maximum rise speed
    kMinSway = .0001; // minimum sway
    kMaxSway = .01; // maximum sway
    kSwayAmplitude = 15;

    SW = Stage.width;
    SH = Stage.height;

    moveHeart = function()
    {
    var a = this.phase + getTimer()*this.sway;
    var sway = Math.sin(a);
    this._x += sway;
    this._rotation = sway*kSwayAmplitude;
    this._y -= this.speed;
    if (this._y < -this._height) {
    this._y = SH+this._height;
    }
    }

    for (i = 1; i <= kNbrHearts; ++i)
    {
    var mc = _root.attachMovie('hearts', 'heart_' + i, i);
    mc._x = random(SW);
    mc._y = random(SH);
    mc.onEnterFrame = moveHeart;
    mc._alpha = 50 + random(50);
    mc.phase = Math.random()*2*Math.PI;
    mc.speed = kMinSpeed + Math.random()*(kMaxSpeed - kMinSpeed);
    mc.sway = kMinSway + Math.random()*(kMaxSway - kMinSway);
    mc.gotoAndStop(random(kNbrPix ) + 1);
    }


    Attached Files Attached Files

  4. #4
    Senior Member
    Join Date
    May 2003
    Posts
    160
    thanks for the responses. that example is sort of what i'm looking for.. i would like the hearts to sway on a sine wave but not stay in one spot while doing so. i was thinking the sine way would be a way for the heart to move left and right on the screen as it floats upward. in your example the heart stays in the same spot and floats upward.

  5. #5
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    Change this line:

    this._x += sway;

    to this:

    this._x += sway*kDistance;

    where kDistance is a larger number like 5 or 10.

  6. #6
    Senior Member
    Join Date
    May 2003
    Posts
    160
    i tried messing with it and can't seem to get it running at a smooth pace, it's either too fast or too slow.

  7. #7
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    I would suggest increasing the frame rate (to 30) if you haven't done so, to add smoothness, and continuing to play with the kMinSpeed and kMaxSpeed numbers. Somewhere between too slow and too fast there must be a 'just right' hiding.

    Also, you might want to turn off the 'sway' stuff till you get the vertical motion right (the adjustments to _y), then work on the sway separately.

    It's best to tweak one number at a time.

  8. #8
    Junior Member
    Join Date
    Apr 2006
    Posts
    1

    Graphic Design Student/Professional

    I am creating a web page for the class I am taking in college. I applied your floating hearts action script to my web page, omitting the hearts graphic and adding a bubble graphic I created. I would My web page has two scenes. Scene one is a game that links to Scene 2 which houses the web pages. When I appy the action script to scene two which is were i would like the bubbles to be, the game opens up without the bubbles showing. However, once I link to the home page of the Scene two and go back to Scene one the bubbles are on scene one. This posses a problem because it effects the movement of the mouse and the game cannot be played properly. Therefore, I have two questions.
    1. Is there anyway I can incorporate the action script so that it only is applied to Scene two and not Scene 1?

    2. Is there any way to link one Flash document to another Flash document without creating separate Scenes? This would allow only the web page to have the action script and not the game

    I am using Macromedia Flas MX 2004. This assignment is for my Senior Capstone project and need HELP!

  9. #9
    Junior Member
    Join Date
    Sep 2000
    Posts
    1
    why do the hearts after a few minutes all end up on left side?

  10. #10
    Junior Member
    Join Date
    Sep 2006
    Posts
    4

    Is there a way to have multiple instances of the effect?

    Is there a way to have multiple instances of the effect? For instance, over the entire stage as a background effect but also coming out of a treasure chest that opens say every two seconds?

    I tried to put the code into its own mc and drop a few instances on the scene but only one will play. Any help is greatly appreciated.

    -R

  11. #11
    Junior Member
    Join Date
    Sep 2006
    Posts
    1

    Modified version

    Im creating a side menu for a web site for college. I have decided to go with 6 menu items in the appearance of bubbles. I would like them to float upwards swaying side to side.

    I have already created the 6 menu items. The modification, obviously, would be the fact that the hearts created were random and there were heaps of them.

    I would like to link just the 6 menu items and have them float up starting in a random position, random speed and random sway movement.

    I know this is alot to ask, i have tried modifying the code above, but im not that familiar with action script.

    Thanks,
    Halidon

  12. #12
    an old dog learning new tricks
    Join Date
    Feb 2003
    Location
    Devon UK
    Posts
    83
    just came across I nice implementation of bubbles

    http://www.freakfish.co.uk/


    if you want a giggle and have the tools, take a look at where the bubbles are coming from!

  13. #13
    Junior Member
    Join Date
    Sep 2006
    Posts
    4
    Here's another instance:
    http://www.aquasphereswim.com/home.html

  14. #14
    Junior Member
    Join Date
    Sep 2006
    Posts
    4

  15. #15
    Member
    Join Date
    May 2007
    Posts
    80
    Hey, i love this bit of AS its exactly what im looking for. im trying to use this code with 1 my image of bubbles, but i only want it to play for 50 frames of the scene, and currently it plays through the whole movie. Do you know how can i stop it from playing at a certain point? and how do i constrain it to a certain area? Many thanks

  16. #16
    Junior Member
    Join Date
    Mar 2008
    Posts
    1
    This is great! I'm also trying to restrain it to a certain area. Any ideas?
    Also, how ca I import it into another fla? I tried everything but it just doesn't work.
    Thanks!!!

  17. #17
    Junior Member
    Join Date
    Nov 2008
    Posts
    1
    Quote Originally Posted by bjones
    why do the hearts after a few minutes all end up on left side?
    Hi All,

    being a newbie to Flash / Actionscript I am struggeling with the same issue, after some time the hearts end up at the left.

    Has anyone got a clue or a solution to make this super .fla even better?

    Kind regards
    Beuvema

  18. #18
    Junior Member
    Join Date
    Oct 2009
    Posts
    1
    I have the exact same problem they all seem ot end up on the left!! Does anyone have a solution for htis or a bit of code that will stop Liability Insurance??

    I await your response!!
    Last edited by lose-it; 09-21-2011 at 05:10 AM.

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

Poll by Flashkit.com