. .
CREATE OR DIE Special Downloads Shop webinale

Schauplatz

CodeSnippets

MovieClip.simulationAuto - Simulieren einer Autobewegung in Flash

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Verwendung

Wer schon immer eine nützliche Methode gesucht hat, um Autosteuerung zu realisieren und hiermit einer als Auto getarnte Movieclip-Instanz über die Bühne zu jagen, dürfte mit dem folgenden prototype seine freude haben. Um die maximale und minimale Geschwindigkeit festzulegen, muss lediglich der Parameter ptempo beim Methodenaufruf gesetzt werden. Unter Einsatz der Methoden sollten Sie ohne weiteres in der Lage sein, ein Autorennspiel oder vergleichbare Spielkonzepte umzusetzen.

Code - Flash MX bis Flash 8
  1. MovieClip.prototype.simulationAuto = function (pTempo)
  2. {
  3. this.tempo = 0;
  4. this.maxTempo = pTempo;
  5. this.minTempo = -pTempo;
  6. this.bewegen = function ()
  7. {
  8. this._y -= this.tempo * Math.cos (this._rotation * (Math.PI / 180));
  9. this._x += this.tempo * Math.sin (this._rotation * (Math.PI / 180));
  10. };
  11. this.onEnterFrame = function ()
  12. {
  13. if (Key.isDown (38))
  14. {
  15. this.tempo += 0.5;
  16. if (this.tempo > this.maxTempo)
  17. {
  18. this.tempo = this.maxTempo;
  19. }
  20. this.bewegen ();
  21. }
  22. else if (Key.isDown (40))
  23. {
  24. this.tempo -= 0.5;
  25. if (this.tempo < this.minTempo)
  26. {
  27. this.tempo = this.minTempo;
  28. }
  29. this.bewegen ();
  30. }
  31. else if (this.tempo < 0)
  32. {
  33. this.tempo += 0.1;
  34. this.bewegen ();
  35. }
  36. else
  37. {
  38. this.tempo -= 0.1;
  39. if (this.tempo < 0)
  40. {
  41. this.tempo = 0;
  42. }
  43. this.bewegen ();
  44. }
  45. if (Key.isDown (37) && this.tempo != 0)
  46. {
  47. this._rotation -= this.tempo;
  48. }
  49. else if (Key.isDown (39) && this.tempo != 0)
  50. {
  51. this._rotation += this.tempo;
  52. }
  53. };
  54. };
  55. ASSetPropFlags (MovieClip.prototype, "simulationAuto", 1);
Anwendung
  1. mc.simulationAuto (5);

Caroline und Matthias Kannengiesser

Tags
    keine Tags
Kommentare
Bisher keine Kommentare