String attached to mouse effect

okay. I was just looking through some templates at template monster
when I cam accross this one:
http://www.templatemonster.com/flash-templates/10335.html

how on earth did they do that effect where the string is attached to the mouse?

omg! this is freaking awesome! you roxorz!

freeskier, you don’t out much, do you?:sigh:

why do you say that?

@Defective: What do you mean?
@BlackBeltNinja: Your welcome :smiley:

Greetings,

I am curious about this string thing because I want to make a Fishing game.

Problem is, I am coding in Visual Basic 6. Do you know any VB6 tutorials on this subject? Or can you add comments along the code in order to explain the functions?

Thanks in advance.

Ha thats nice - might be good to post in source/experiments

Alright here is a commented version :D. I also made a graphic to kind of show what it is doing.

@stringy: I’ll post in in Source/experiments in a bit :smiley:

MovieClip.prototype.DrawCircle=function(x,y,r){
   //Draw the circle with some basic trigonometry
   //In VB you could draw the circle with the GDI's Ellipse function
this.moveTo(x+r,y);
    this.beginFill("0xFBFFA4",100);
    for(var t=0;t<Math.PI*2;t+=.5){
        this.lineTo(x+r*Math.cos(t),y+r*Math.sin(t));
        }
    this.endFill();
    }
//Declare a function to return the angle in radians formed by the two points
FindAngle = function (x1, x2, y1, y2) {
    return Math.atan2(y2-y1, x2-x1);
    };
//Declare a function to find the distance between the two points
Distance=function(x1,x2,y1,y2){
    return Math.sqrt(Math.pow(x2-x1,2)+Math.pow(y2-y1,2));
}
//Declare a function to return an area of N points that are equally 
//divided among the line (x1,y1)(x2,y2) 
Interpolate=function(x1,y1,x2,y2,n){
    //find the distance and angle between point a and b  
    var dist= Distance(x1,x2,y1,y2);
    var ang = FindAngle(x1,x2,y1,y2);
    //create an array to store the points that will be returned
    var points = [];
    //divide the distance from the start to the end by the number of points     
    //you wish to return, and use that and the angle to find out where 
    //each point on the line is, and push it into the points array (you'll have to    
    //use the stack class in VB I think
    for(var l = 0;l<=dist;l+=dist/n){
        var x =x1+l*Math.cos(ang);
        var y = y1+l*Math.sin(ang);
        //push a point object onto the stack. With the Graphics GDI in VB 
        //you can use the point struct like points.push(new Point(x,y));
        points.push({x:x,y:y});
        }
    //return the array of all of the points
    return points;
    }
//Define a function to draw an array of points with a circle on the end
DrawNodes=function(array){
    //create a movieclip for the string
    //in vb it is like initializing your  Graphics class.
    _root.createEmptyMovieClip("line",1).lineStyle(1,0xFFFFFF,40);
    //start the line at the point at the beginning of the array of points
    line.moveTo(array[0].x,array[0].y);
    //continue drawing the line to all of the other points in the array.
    for(var i = 1; i<array.length-1;i++){
        line.lineTo(array*.x,array*.y);
    }
    //draw a circle at the 2nd to the end of the array 
    //(the very end was doing some wierd things, so I was lazy and used the
    //2nd to end :P)
    line.DrawCircle(array[array.length-2].x,array[array.length-2].y,5);
}
//initially set the string to be at the perfect line from (275,0) to the mouse //and have it set to make 15 points in the line.
currentnodes=gotonodes=Interpolate(275,0,_xmouse,_ymouse,15);
onMouseMove=function(){
    //when the mouse moves make the gotonodes equal to an array of points
    //that form a straight line from (275,0) to the mouse
    gotonodes=Interpolate(275,0,_xmouse,_ymouse,15);
    }
// on every frame (could be achieved with a timer tick event)
onEnterFrame=function(){
   //Go through and ease all of the current nodes to the goto nodes.
   //The Nodes closer to the top are eased more than the ones at the bottom
    for(var node in gotonodes){
        currentnodes[node].x=currentnodes[node].x+(gotonodes[node].x-currentnodes[node].x)/(node/2+1);
        currentnodes[node].y=currentnodes[node].y+(gotonodes[node].y-currentnodes[node].y)/(node/2+1);
        }
    //Draw the current nodes as a string
    DrawNodes(currentnodes);
    }

Hope this helps!
-freeskier89 :slight_smile:

good work freeskier

http://www.fingertime.com/harpoonlagoon.php

Note the harpoon rope in this game. It’s awesome! Actually, this little game caught me in all this “elastic rope mania”. I said what! A 650 Kb Flash game has such a rope sim? I want a rope sim, too!

Note also the hanging of the rope when the harpoon is almost horizontal, as well as the rope’s reaction to the slightest vibration. When the harpoon is shot into the water, the rope’s reaction is equally realistic, too.

PS freeskier89 thanx for the comments and the image.