NEU: Alle Visual Codes als Code Snippets für Flash CS5:
jetzt hier downloaden .

Maus Anziehen

Code Actionscript 2.0

Instanz-Aktion

onClipEvent (load) {
startx = this._x;
starty = this._y;
mindistance = 160.0;
}
onClipEvent (enterFrame) {
softness_mouse = 4.0;
softness_start = 6.0;
dx = this._x - _root._xmouse;
dy = this._y - _root._ymouse;
distance = Math.sqrt(dx * dx + dy * dy);
if (distance < mindistance) {
//slide towards mouse
this._x = this._x - dx / softness_mouse;
this._y = this._y - dy / softness_mouse;
} else {
// slide back to starting point
this._x = this._x + (startx - this._x) / softness_start;
this._y = this._y + (starty - this._y) / softness_start;
}
}

Code Actionscript 3.0

addEventListener(Event.ENTER_FRAME, enterFrame); var startx = square.x; var starty = square.y; var mindistance = 160.0; function enterFrame(event:Event){ var softness_mouse = 4; var softness_start = 6; var dx = square.x - mouseX; var dy = square.y - mouseY; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < mindistance) { //slide towards mouse square.x = square.x - dx/ softness_mouse; square.y = square.y - dy/ softness_mouse; } else { // slide back to starting point square.x = square.x + (startx -square.x) /softness_start; square.y = square.y + (starty - square.y) / softness_start; } }

Infos

Ein Objekt wird von der Maus angezogen, sobald sie näher als mindistance kommt. Andernfalls rutscht es an den Ausgangspunkt zurück. Beide Bewegungen sind abgefederte Bewegungen. Die Divisoren softness_mouse und softness_start bestimmen die Weichheit der Bewegungen.

verwandt mit: Bewegung zu Ziel, Maus verfolgen

Download

Right click: Flashfile AS 2.0 | Flashfile AS 3.0 | SWF-File


Share