dcsimg
A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: bubbles moving away from cursor

  1. #1
    Junior Member
    Join Date
    Sep 2007
    Posts
    2

    bubbles moving away from cursor

    I need some help! I am developing a flash movie where a series of bubbles softly and continuously float up from the bottom of the screen to the top. When someone mouses over and area of the bubbles, the bubbles need to softly repel away from the cursor and continue floating away from the cursor. Does any one know a script or an example of a source code or file that has or is similar to this functionality?

  2. #2
    Senior Member
    Join Date
    Aug 2007
    Posts
    141
    This is just for the bubbles moving from the bottom to top of screen.

    Code:
    // Make sure you've got a mc with the linkage id "bubbleID".
    // What you set for your fps will also effect the speed of the bubble movement.
    function createBubble()  {
    	var holder:MovieClip = this.attachMovie("bubbleID","newBubble" + this.getNextHighestDepth(),this.getNextHighestDepth());
    	holder._y = Stage.height + holder._height;
    	holder._xscale = holder._yscale = Math.random() * 75 + 25;
    	holder.orgX = Math.random() * Stage.width;
    	holder.sinX = 2 * Math.random() * Math.PI;
    	holder.changeX = Math.random() * 0.1 + 0.05;
    	holder.changeY = Math.random() * 2 + 2;
    	holder.scaleUp = Math.random() * 40 + 10;
    	holder.onEnterFrame = function()  {
    		this._x = this.orgX + Math.sin(this.sinX+=this.changeX) * this.scaleUp;
    		this._y -= this.changeY;
    	}
    }
    
    setInterval(this, "createBubble", 250);

  3. #3
    Senior Member Alluvian's Avatar
    Join Date
    Jun 2006
    Posts
    967
    I like the bubble movement code, MC.

    Here is a quick and dirty stab at making them afraid of the mouse. Just a few additions. This was played with at 24 frames per second. Not super happy with the effect, the bubbles get 'stuck' below the mouse too easily it would look nicer if the slipped around the outside more easily instead of moving back and forth at the maxrange of the mouse effect.

    Well, it's better than nothing. Feel free to play with the variables mousethreshold (the 'range' of the mouse effect, in pixels), and maxmousemove (the speed at which the bubbles move away from the mouse, they move away slower the further away they are, and don't move away at all when out of the threshold range).

    PHP Code:
    // Make sure you've got a mc with the linkage id "bubbleID".
    // What you set for your fps will also effect the speed of the bubble movement.
    function createBubble()  {
        var 
    holder:MovieClip this.attachMovie("bubbleID","newBubble" this.getNextHighestDepth(),this.getNextHighestDepth());
        
    holder._y Stage.height holder._height;
        
    holder._xscale holder._yscale Math.random() * 75 25;
        
    holder.orgX Math.random() * Stage.width;
        
    holder.sinX Math.random() * Math.PI;
        
    holder.changeX Math.random() * 0.1 0.05;
        
    holder.changeY Math.random() * 2;
        
    holder.scaleUp Math.random() * 40 10;
        
        
    mousethreshold 100;
        
    maxmousemove 20;
        
    holder.onEnterFrame = function()  {
            
    //natural movement
            
    this._x this.orgX Math.sin(this.sinX+=this.changeX) * this.scaleUp;
            
    this._y -= this.changeY;
            
    //correction for mouselocation
            
    var mousedist Math.sqrt(Math.pow(this._x _xmouse,2) + Math.pow(this._y _ymouse,2));
            if (
    mousedist mousethreshold) {
                var 
    moverate maxmousemove -((maxmousemove/mousethreshold)*mousedist);
                if (
    this._x<_xmouse) {this._x -= moverate} else {this._x += moverate}
                if (
    this._y<_ymouse) {this._y -= moverate} else {this._y += moverate}
            }
        }
    }

    setInterval(this"createBubble"150); 

  4. #4
    Developing For Dunkets mneil's Avatar
    Join Date
    Mar 2007
    Location
    Lincoln City
    Posts
    2,156
    Man, the code is right on for moving the bubbles, but those jerks just get stuck. It's the code that sets the wavy movement in motion that get them and I can't seem to get it right either. I stared at this for a little bit and got them to not stick but it causes them to jump at the halfway mark. Maybe someone else will fix that. I also did a removeMovieClip() to save some poor processor:
    PHP Code:
    // Make sure you've got a mc with the linkage id "bubbleID".
    // What you set for your fps will also effect the speed of the bubble movement.
    function createBubble()  {
        var 
    holder:MovieClip this.attachMovie("bubbleID","newBubble" this.getNextHighestDepth(),this.getNextHighestDepth());
        
    holder._y Stage.height holder._height;
        
    holder._xscale holder._yscale Math.random() * 75 25;
        
    holder.orgX Math.random() * Stage.width;
        
    holder.sinX Math.random() * Math.PI;
        
    holder.changeX Math.random() * 0.1 0.05;
        
    holder.changeY Math.random() * 2;
        
    holder.scaleUp Math.random() * 40 10;
        
        
    mousethreshold 100;
        
    maxmousemove 20;
        
    holder.onEnterFrame = function()  {
            
    //natural movement
             
    this._y -= this.changeY;
            
    //correction for mouselocation
            
    var mousedist Math.sqrt(Math.pow(this._x _xmouse,2) + Math.pow(this._y _ymouse,2));
            if (
    mousedist mousethreshold) {
                var 
    moverate maxmousemove -((maxmousemove/mousethreshold)*mousedist);
                if (
    this._x<_xmouse) {this._x -= moverate} else {this._x += moverate}
                if (
    this._y<_ymouse) {this._y -= moverate} else {this._y += moverate}

            }else{
    //Keep bubbles from getting stuck
                
    this._x this.orgX Math.sin(this.sinX+=this.changeX) * this.scaleUp;
            }
            
    //remove the clips
            
    if(this._y <= -this._height){
                
    this.removeMovieClip();
            }
        }
    }

    setInterval(this"createBubble"150); 
    http://code.mneilsworld.com/
    Text Effects | Bubbles | Dynamic Resize
    4 weeks , 20 papers ... thats 2 dollars .....Caassshhh!

  5. #5
    It's true..I brought sexy back smith1302's Avatar
    Join Date
    Sep 2005
    Location
    here
    Posts
    343
    that is a reallly cool script. Can i use that script whoever made it? I wanna use it during a loading menu.
    Hey check out my arcade sites!
    Ninja Games | WW2 Games

  6. #6
    Junior Member
    Join Date
    Sep 2007
    Posts
    2

    how do i get the bubbles to float out from one area

    The bubble script is amazing thanks so much. I have to make it so that the bubbles fly out of an object about 200 pixels wide on the screen so how do i make it so that the bubbles float up from a static object located on the stage? I tried playing with the x & y values but the bubbles still float down to the bottom of the stage.

    Can anyone help me please???

  7. #7
    Senior Member
    Join Date
    Aug 2007
    Posts
    141
    Quote Originally Posted by smith1302
    that is a reallly cool script. Can i use that script whoever made it? I wanna use it during a loading menu.
    Feel free to use the following script...

    Code:
    // Make sure you've got a mc with the linkage id "bubbleID".
    // What you set for your fps will also effect the speed of the bubble movement.
    function createBubble()  {
    	var holder:MovieClip = this.attachMovie("bubbleID","newBubble" + this.getNextHighestDepth(),this.getNextHighestDepth());
    	holder._y = Stage.height + holder._height;
    	holder._xscale = holder._yscale = Math.random() * 75 + 25;
    	holder.orgX = Math.random() * Stage.width;
    	holder.sinX = 2 * Math.random() * Math.PI;
    	holder.changeX = Math.random() * 0.1 + 0.05;
    	holder.changeY = Math.random() * 2 + 2;
    	holder.scaleUp = Math.random() * 40 + 10;
    	holder.onEnterFrame = function()  {
    		this._x = this.orgX + Math.sin(this.sinX+=this.changeX) * this.scaleUp;
    		this._y -= this.changeY;
    	}
    }
    
    setInterval(this, "createBubble", 250);
    how do i make it so that the bubbles float up from a static object located on the stage?
    Try this...

    Code:
    // Make sure you've got a mc with the linkage id "bubbleID".
    // Set the registration point to the top left corner.
    // What you set for your fps will also effect the speed of the bubble movement.
    
    // The box where bubbles will emerge from.
    this.createEmptyMovieClip("rec",this.getNextHighestDepth());
    rec._x = 300;
    rec._y = 350;
    rec.beginFill(0xff0000,100);
    rec.moveTo(0,0);
    rec.lineTo(100,0);
    rec.lineTo(100,100);
    rec.lineTo(0,100);
    rec.endFill();
    
    function createBubble()  {
    	var holder:MovieClip = this.attachMovie("bubbleID","newBubble" + this.getNextHighestDepth(),this.getNextHighestDepth());
    	holder._x = holder.orgX = rec._x + Math.random() * rec._width;
    	holder._y = rec._y + holder._width;
    	holder._xscale = holder._yscale = Math.random() * 75 + 25;
    	holder.sinX = 2 * Math.random() * Math.PI;
    	holder.changeX = Math.random() * 0.1 + 0.05;
    	holder.changeY = Math.random() * 2 + 2;
    	holder.scaleUp = Math.random() * 40 + 10;
    	holder.onEnterFrame = function()  {
    		this._x = this.orgX + Math.sin(this.sinX+=this.changeX) * this.scaleUp;
    		this._y -= this.changeY;
    	}
    }
    
    setInterval(this, "createBubble", 250);

  8. #8
    Junior Member
    Join Date
    Jul 2008
    Posts
    1
    yes, awesome script. I am trying to alter it so the bubbles drift to the right of the static object and expand away from each other. like they are blowing in the wind.

    Any ideas. I tried making a drift function but can't get anything to work.

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