• beyond tellerrand – play. Register Now!
Zurück   Flashforum > Flash > Flash Fortgeschritten > Flash MX

Antwort
 
LinkBack Themen-Optionen Ansicht
Alt 01-09-2004, 11:27   #1 (permalink)
...
 
Benutzerbild von dimmid
 
Registriert seit: Nov 2002
Ort: hinterm mond
Beiträge: 1.732
käferanimation soll maus folgen

also: ich hab einen kleinen käfer, den ich auf meinen
seiten zum laufen bringen will. folgende punkte sind
mir wichtig:
1. er soll der maus folgen
2. er soll dies im gleichmäßigen tempo tun (nicht mal
schnell, mal langsam)
3. er muß sich der maus zuwenden (also rotieren)
4. er darf nur auf einer begrenzten fläche laufen

so weit so gut, hab also mit meinem bescheidenen
wissen über actionscript begonnen punkt eins zu
realisieren. sieht so aus:
onClipEvent (enterFrame) {
_x = _x+_xmouse/150;
_y = _y+_ymouse/150;
}

jetzt häng ich fest. hab zwar was zu rotation und
begrenzung gefunden, kann das aber nicht mit dem
bisheringen script verbinden.

für alle die helfen können:
>> hier der bisherige stand
>> hier zum downloaden
__________________
»there´s a hole in the world like a great black pit
and it´s filled with people who are filled with sh!t«
dimmid ist offline   Mit Zitat antworten
Alt 01-09-2004, 11:32   #2 (permalink)
Farbe ist Luxus
 
Benutzerbild von ludabruda
 
Registriert seit: May 2003
Ort: Köln
Beiträge: 2.405
Hi,

du kannst den Winkel zwischen zwei Punkten mit Math.atan2(dy,dx) berechnen. Den musst du nur noch ins Gradmaß umrechnen und der _rotation zuweisen...

Zusätzlich packst du in dein onEnterFrame vor der Zuweisung der _x und _y Werte eine Abfrage a la: if(_x < 100 && _x > 0 && _y > 0 && _y < 100) { ... }

Grüße
Sascha
__________________
12:15, press return
ludabruda ist offline   Mit Zitat antworten
Alt 01-09-2004, 11:36   #3 (permalink)
...
 
Benutzerbild von dimmid
 
Registriert seit: Nov 2002
Ort: hinterm mond
Beiträge: 1.732
danke, hab die begrenzung mal wie beschrieben probiert.
sieht jetzt so aus:
onClipEvent (enterFrame) {
if (_x < 500 && _x > 50 && _y >0 && _y < 500){
_x = _x+_xmouse/150;
_y = _y+_ymouse/150;}
}

geht leider nur bedingt so. sobald der käfer die begrenzung
erreicht, bleibt er stehen und macht gar nix mehr.

zur rotation hab ich das gefunden:
posX = _root._xmouse-_x;
posY = _root._ymouse-_y;
_rotation = -(Math.atan2(posX,posY)*(180/Math.PI));
}

weiß leider nicht, wie ich es richtig ins script setze!
__________________
»there´s a hole in the world like a great black pit
and it´s filled with people who are filled with sh!t«

Geändert von dimmid (01-09-2004 um 11:45 Uhr)
dimmid ist offline   Mit Zitat antworten
Alt 01-09-2004, 15:07   #4 (permalink)
...
 
Benutzerbild von dimmid
 
Registriert seit: Nov 2002
Ort: hinterm mond
Beiträge: 1.732
falls es jemanden interessiert ... ich habs soweit geschafft,
daß der käfer in gleichmäßigem tempo dem mauszeiger folgt
und immer schön mim kopf vorran läuft

hier die lösung:
auf einem mc auf der hauptbühne liegt dieses script:
onClipEvent (load) {
v = 3;
}
onClipEvent (mouseMove) {
sollX = _root._xmouse;
sollY = _root._ymouse;
deltaX = sollX-_x;
deltaY = sollY-_y;
deltaS = Math.sqrt(deltaX*deltaX+deltaY*deltaY);
frame = int(deltaS/v);
index = 0;
lauf = true;
faktorX = deltaX/frame;
faktorY = deltaY/frame;
}
onClipEvent (enterFrame) {
if (index++ != frame && lauf) {
_x += faktorX;
_y += faktorY;
} else {
_x = sollX;
_y = sollY;
lauf = false;
}
}

und in diesen mc kommt mein animierter käfer-mc rein.
auf den leg ich dann dieses script:
onClipEvent (mouseMove) {
_rotation = Math.atan2(_parent._y-_root._ymouse, _parent._x-_root._xmouse)/Math.PI*180-90;
}

jetzt muß ich nurnoch die bewegungs-begrenzung hinbekom-
men. also wenn jemand weiter weiß ... ich würd mich freuen
__________________
»there´s a hole in the world like a great black pit
and it´s filled with people who are filled with sh!t«
dimmid ist offline   Mit Zitat antworten
Alt 01-09-2004, 15:13   #5 (permalink)
Farbe ist Luxus
 
Benutzerbild von ludabruda
 
Registriert seit: May 2003
Ort: Köln
Beiträge: 2.405
Für die Begrenzung frag am besten nicht den aktuellen Wert sondern den Wert nach Addition ab:

ActionScript:
  1. newX = _x+_root._xmouse/150;
  2. newY = _y+_root._ymouse/150;
  3. if (newX < 500 && newX > 50 && newY >0 && newY < 500){
  4. ...
  5. }

Dann sollte es gehen.

Grüße
Sascha
__________________
12:15, press return
ludabruda ist offline   Mit Zitat antworten
Alt 01-09-2004, 16:04   #6 (permalink)
...
 
Benutzerbild von dimmid
 
Registriert seit: Nov 2002
Ort: hinterm mond
Beiträge: 1.732
danke, ich habs!
__________________
»there´s a hole in the world like a great black pit
and it´s filled with people who are filled with sh!t«
dimmid ist offline   Mit Zitat antworten
Alt 01-09-2004, 18:54   #7 (permalink)
nobody is perfect
 
Benutzerbild von Decrone
 
Registriert seit: Apr 2002
Ort: Bremen
Beiträge: 3.049
Hi

ich hab mal ein bisschen Lust gehabt das ganze im MX-Style zu ändern


ActionScript:
  1. //Code auf Frame 1 / Hzl
  2. MovieClip.prototype.krabbeln = function(v){
  3.     this.onEnterFrame = function(){
  4.         this.newX = this._x+_root._xmouse/150;
  5.         this.newY = this._y+_root._ymouse/150;
  6.         if (this.newX < 540 && this.newX > 70 && this.newY >30 && this.newY < 510){
  7.             this.play();
  8.             if (this.index++ != this.frame && this.lauf) {
  9.                 this._x += this.faktorX;
  10.                 this._y += this.faktorY;
  11.             } else {
  12.                 this._x = this.sollX;
  13.                 this._y = this.sollY;
  14.                 this.lauf = false;
  15.                 this.gotoAndStop("stoppen");
  16.             }
  17.         }else{
  18.             this.gotoAndStop("stoppen");
  19.         }
  20.     }
  21.     this.onMouseMove = function(){
  22.         this._rotation = Math.atan2(this._y-_root._ymouse, this._x-_root._xmouse)/Math.PI*180-90;
  23.         this.sollX = _root._xmouse;
  24.         this.sollY = _root._ymouse;
  25.         this.deltaX = this.sollX-this._x;
  26.         this.deltaY = this.sollY-this._y;
  27.         this.deltaS = Math.sqrt(this.deltaX*this.deltaX+this.deltaY*this.deltaY);
  28.         this.frame = int(this.deltaS/v);
  29.         this.index = 0;
  30.         this.lauf = true;
  31.         this.faktorX = this.deltaX/this.frame;
  32.         this.faktorY = this.deltaY/this.frame;
  33.     }
  34. }
  35. kaefer1.krabbeln(3);//Hiermit rufst Du das ganze auf!
  36. kaefer2.krabbeln(4);

Anbei hab ich im Anhang ein zweites Krabbeltierchen intrigiert. Sieht lustig aus das ganze Siehe Download!

Und hier zum Downloaden

bye
__________________
FF Unterstützen! Erste Hilfe! häufig gestellten Fragen
...................... ............... ................................

Geändert von Decrone (01-09-2004 um 18:58 Uhr)
Decrone ist offline   Mit Zitat antworten
Antwort

Lesezeichen

Themen-Optionen
Ansicht

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks sind an
Pingbacks sind an
Refbacks sind an



Alle Zeitangaben in WEZ +1. Es ist jetzt 22:03 Uhr.

Domains, Webhosting & Vserver von Host Europe
Unterstützt das Flashforum!
Adobe User Group


Copyright ©1999 – 2012 Marc Thiele