weitere MCs bearbeiten [Flash 10]
| Beiträge: 69 Registriert: Apr 2013
| 30.06.2013, 22:13
Hallo zusammen !
Ich hab da ein fertiges Script, wo eine Kugel an 5 Linien herunter rollt.
Ich möchte nun weitere Kugeln einsätzen, die nach einer bestimmten Zeit auch an den Linien
herunter rollen.Das Ganze liegt auf der Bühne und das währe mir auch am liebsten, so kann ich die Kugel vor oder hinter anderen MCs langführen.
Ich hab jetzt schon einige Stunden rumprobiert und die Kugel von der Bühne genommen um sie
mit einer Schleife zu duplizieren.Das ging auch aber es wird immer nur eine Kugel benutzt und
die anderen bewegen sich nicht.
Ich hoffe einer kann mir da weiter helfen ?
ActionScript:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | var vx:Number = 0;
var vy:Number = 0;
var gravity:Number = .5;
var bounce:Number = -0.7;
var left:Number = 0;
var right:Number = Stage.width;
var top:Number = 0;
var bottom:Number = Stage.height;
var dragging:Boolean = false;
var oldX:Number;
var oldY:Number;
function onEnterFrame():Void
{
if(dragging)
{
vx = ball._x - oldX;
vy = ball._y - oldY;
oldX = ball._x;
oldY = ball._y;
}
else
{
vy += gravity;
ball._x += vx;
ball._y += vy;
for(var i:Number = 0;i<5;i++)
{
checkLine(this["line" + i]);
}
if(ball._x + ball._width / 2 > right)
{
ball._x = right - ball._width / 2;
vx *= bounce;
}
else if(ball._x - ball._width / 2 < left)
{
ball._x = left + ball._width / 2;
vx *= bounce;
}
if(ball._y + ball._height / 2 > bottom)
{
ball._y = bottom - ball._height / 2;
vy *= bounce;
}
else if(ball._y - ball._height / 2< top)
{
ball._y = top + ball._height / 2;
vy *= bounce;
}
}
}
function checkLine(line:MovieClip)
{
var bounds:Object = line.getBounds(this);
if(ball._x > bounds.xMin && ball._x < bounds.xMax)
{
// get angle, sine and cosine
var angle:Number = line._rotation * Math.PI / 180;
var cosine:Number = Math.cos(angle);
var sine:Number = Math.sin(angle);
// get position of ball, relative to line
var x:Number = ball._x - line._x;
var y:Number = ball._y - line._y;
// rotate line
var y1:Number = cosine * y - sine * x;
var vy1:Number = cosine * vy - sine * vx;
if(y1 > -ball._height / 2 && y1 < vy1)
{
// rotate line
var x1:Number = cosine * x + sine * y;
// rotate velocity
var vx1:Number = cosine * vx + sine * vy;
// perform bounce with rotated values
y1 = -ball._height / 2;
vy1 *= bounce;
// rotate everything back
x = cosine * x1 - sine * y1;
y = cosine * y1 + sine * x1;
vx = cosine * vx1 - sine * vy1;
vy = cosine * vy1 + sine * vx1;
// reset actual ball position
ball._x = line._x + x;
ball._y = line._y + y;
}
}
}
ball.onPress = function()
{
oldX = this._x;
oldY = this._y;
dragging = true;
this.startDrag();
}
ball.onRelease = ball.onRelease = function()
{
dragging = false;
this.stopDrag();
}
|
| |
| Ähnliche Beiträge zum Thema | |
|
Flashhilfe.de Flash Platform Tipps & Tutorials Flash Platform Andere Programmiersprachen Jobangebote Diskussionen
Flashhilfe News
Regeln & Bedingungen
|