Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

second update for tween system

  • Loading branch information...
commit e1f53be1952aa15e0c2718b5c54ebbac156b4702 1 parent 382915d
@Beeblerox Beeblerox authored
View
6 src/org/flixel/tweens/misc/MultiVarTween.hx
@@ -23,6 +23,12 @@ class MultiVarTween extends FlxTween
super(0, type, complete);
}
+ override public function destroy():Void
+ {
+ super.destroy();
+ _object = null;
+ }
+
/**
* Tweens multiple numeric public properties.
* @param object The object containing the properties.
View
6 src/org/flixel/tweens/misc/VarTween.hx
@@ -18,6 +18,12 @@ class VarTween extends FlxTween
super(0, type, complete);
}
+ override public function destroy():Void
+ {
+ super.destroy();
+ _object = null;
+ }
+
/**
* Tweens a numeric public property.
* @param object The object containing the property.
View
1  src/org/flixel/tweens/motion/CircularMotion.hx
@@ -1,6 +1,5 @@
package org.flixel.tweens.motion;
-import nme.geom.Point;
import org.flixel.tweens.FlxTween;
import org.flixel.tweens.util.Ease;
View
1  src/org/flixel/tweens/motion/CubicMotion.hx
@@ -1,7 +1,6 @@
package org.flixel.tweens.motion;
import org.flixel.tweens.FlxTween;
-import nme.geom.Point;
import org.flixel.tweens.util.Ease;
/**
View
1  src/org/flixel/tweens/motion/LinearMotion.hx
@@ -2,7 +2,6 @@
import org.flixel.tweens.FlxTween;
import org.flixel.tweens.util.Ease;
-import nme.geom.Point;
/**
* Determines motion along a line, from one point to another.
View
86 src/org/flixel/tweens/motion/LinearPath.hx
@@ -1,8 +1,8 @@
package org.flixel.tweens.motion;
+import org.flixel.FlxPoint;
import org.flixel.tweens.FlxTween;
import org.flixel.tweens.util.Ease;
-import nme.geom.Point;
/**
* Determines linear motion along a set of points.
@@ -16,15 +16,26 @@ class LinearPath extends Motion
*/
public function new(?complete:CompleteCallback, ?type:Int = 0)
{
- _points = new Array<Point>();
+ super(0, complete, type, null);
+ _points = new Array<FlxPoint>();
_pointD = new Array<Float>();
_pointT = new Array<Float>();
distance = _speed = _index = 0;
-
- super(0, complete, type, null);
+
_pointD[0] = _pointT[0] = 0;
}
+
+ override public function destroy():Void
+ {
+ super.destroy();
+ _points = null;
+ _pointD = null;
+ _pointT = null;
+ _last = null;
+ _prevPoint = null;
+ _nextPoint = null;
+ }
/**
* Starts moving along the path.
@@ -67,7 +78,7 @@ class LinearPath extends Motion
distance += Math.sqrt((x - _last.x) * (x - _last.x) + (y - _last.y) * (y - _last.y));
_pointD[_points.length] = distance;
}
- _points[_points.length] = _last = new Point(x, y);
+ _points[_points.length] = _last = new FlxPoint(x, y);
}
/**
@@ -75,7 +86,7 @@ class LinearPath extends Motion
* @param index Index of the point.
* @return The Point object.
*/
- public function getPoint(?index:Int = 0):Point
+ public function getPoint(?index:Int = 0):FlxPoint
{
if (_points.length == 0)
{
@@ -87,7 +98,15 @@ class LinearPath extends Motion
/** @private Starts the Tween. */
override public function start():Void
{
- _index = 0;
+ if (!_backward)
+ {
+ _index = 0;
+ }
+ else
+ {
+ _index = _points.length;
+ }
+
super.start();
}
@@ -95,17 +114,42 @@ class LinearPath extends Motion
override public function update():Void
{
super.update();
- if (_index < _points.length - 1)
+ var td:Float;
+ var tt:Float;
+
+ if (!_backward)
+ {
+ if (_index < _points.length - 1)
+ {
+ while (_t > _pointT[_index + 1]) _index ++;
+ }
+ td = _pointT[_index];
+ tt = _pointT[_index + 1] - td;
+ td = (_t - td) / tt;
+ _prevPoint = _points[_index];
+ _nextPoint = _points[_index + 1];
+ x = _prevPoint.x + (_nextPoint.x - _prevPoint.x) * td;
+ y = _prevPoint.y + (_nextPoint.y - _prevPoint.y) * td;
+ }
+ else
{
- while (_t > _pointT[_index + 1]) _index ++;
+ if (_index > 0)
+ {
+ while (_t < _pointT[_index - 1])
+ {
+ _index -= 1;
+ }
+ }
+ td = _pointT[_index];
+ tt = _pointT[_index - 1] - td;
+ td = (_t - td) / tt;
+ _prevPoint = _points[_index];
+ _nextPoint = _points[_index - 1];
+ x = _prevPoint.x + (_nextPoint.x - _prevPoint.x) * td;
+ y = _prevPoint.y + (_nextPoint.y - _prevPoint.y) * td;
}
- var td:Float = _pointT[_index];
- var tt:Float = _pointT[_index + 1] - td;
- td = (_t - td) / tt;
- _prevPoint = _points[_index];
- _nextPoint = _points[_index + 1];
- x = _prevPoint.x + (_nextPoint.x - _prevPoint.x) * td;
- y = _prevPoint.y + (_nextPoint.y - _prevPoint.y) * td;
+
+ super.postUpdate();
}
/** @private Updates the path, preparing it for motion. */
@@ -117,7 +161,7 @@ class LinearPath extends Motion
var i:Int = 0;
while (i < _points.length)
{
- _pointT[i] = _pointD[i ++] / distance;
+ _pointT[i] = _pointD[i++] / distance;
}
}
@@ -133,14 +177,14 @@ class LinearPath extends Motion
private function getPointCount():Float { return _points.length; }
// Path information.
- private var _points:Array<Point>;
+ private var _points:Array<FlxPoint>;
private var _pointD:Array<Float>;
private var _pointT:Array<Float>;
private var _speed:Float;
private var _index:Int;
// Line information.
- private var _last:Point;
- private var _prevPoint:Point;
- private var _nextPoint:Point;
+ private var _last:FlxPoint;
+ private var _prevPoint:FlxPoint;
+ private var _nextPoint:FlxPoint;
}
View
23 src/org/flixel/tweens/motion/Motion.hx
@@ -1,5 +1,6 @@
package org.flixel.tweens.motion;
+import org.flixel.FlxObject;
import org.flixel.tweens.FlxTween;
import org.flixel.tweens.util.Ease;
@@ -18,6 +19,8 @@ class Motion extends FlxTween
*/
public var y:Float;
+ private var _object:FlxObject;
+
/**
* Constructor.
* @param duration Duration of the Tween.
@@ -31,8 +34,28 @@ class Motion extends FlxTween
super(duration, type, complete, ease);
}
+ override public function destroy():Void
+ {
+ super.destroy();
+ _object = null;
+ }
+
override public function update():Void
{
super.update();
}
+
+ public function setObject(object:FlxObject):Void
+ {
+ _object = object;
+ }
+
+ public function postUpdate():Void
+ {
+ if (_object != null)
+ {
+ _object.x = x;
+ _object.y = y;
+ }
+ }
}
View
10 src/org/flixel/tweens/motion/QuadMotion.hx
@@ -1,8 +1,8 @@
package org.flixel.tweens.motion;
+import org.flixel.FlxPoint;
import org.flixel.tweens.FlxTween;
import org.flixel.tweens.util.Ease;
-import nme.geom.Point;
/**
* Determines motion along a quadratic curve.
@@ -10,8 +10,8 @@ import nme.geom.Point;
class QuadMotion extends Motion
{
- public static var point:Point = new Point();
- public static var point2:Point = new Point();
+ public static var point:FlxPoint = new FlxPoint();
+ public static var point2:FlxPoint = new FlxPoint();
/**
* Constructor.
@@ -91,8 +91,8 @@ class QuadMotion extends Motion
private function getDistance():Float
{
if (_distance >= 0) return _distance;
- var a:Point = QuadMotion.point;
- var b:Point = QuadMotion.point2;
+ var a:FlxPoint = QuadMotion.point;
+ var b:FlxPoint = QuadMotion.point2;
a.x = x - 2 * _controlX + _toX;
a.y = y - 2 * _controlY + _toY;
b.x = 2 * _controlX - 2 * x;
View
110 src/org/flixel/tweens/motion/QuadPath.hx
@@ -1,8 +1,8 @@
package org.flixel.tweens.motion;
+import org.flixel.FlxPoint;
import org.flixel.tweens.FlxTween;
import org.flixel.tweens.util.Ease;
-import nme.geom.Point;
/**
* A series of points which will determine a path from the
@@ -17,17 +17,29 @@ class QuadPath extends Motion
*/
public function new(?complete:CompleteCallback, ?type:Int = 0)
{
- _points = new Array<Point>();
- _curve = new Array<Point>();
+ super(0, complete, type, null);
+ _points = new Array<FlxPoint>();
+ _curve = new Array<FlxPoint>();
_curveD = new Array<Float>();
_curveT = new Array<Float>();
_distance = _speed = _index = 0;
_updateCurve = true;
- super(0, complete, type, null);
_curveT[0] = 0;
}
+ override public function destroy():Void
+ {
+ super.destroy();
+ _points = null;
+ _curve = null;
+ _curveD = null;
+ _curveT = null;
+ _a = null;
+ _b = null;
+ _c = null;
+ }
+
/**
* Starts moving along the path.
* @param duration Duration of the movement.
@@ -64,8 +76,8 @@ class QuadPath extends Motion
public function addPoint(?x:Float = 0, ?y:Float = 0):Void
{
_updateCurve = true;
- if (_points.length == 0) _curve[0] = new Point(x, y);
- _points[_points.length] = new Point(x, y);
+ if (_points.length == 0) _curve[0] = new FlxPoint(x, y);
+ _points[_points.length] = new FlxPoint(x, y);
}
/**
@@ -73,7 +85,7 @@ class QuadPath extends Motion
* @param index Index of the point.
* @return The Point object.
*/
- public function getPoint(?index:Int = 0):Point
+ public function getPoint(?index:Int = 0):FlxPoint
{
if (_points.length == 0)
{
@@ -85,7 +97,15 @@ class QuadPath extends Motion
/** @private Starts the Tween. */
override public function start():Void
{
- _index = 0;
+ if (!_backward)
+ {
+ _index = 0;
+ }
+ else
+ {
+ _index = _curve.length;
+ }
+
super.start();
}
@@ -93,18 +113,45 @@ class QuadPath extends Motion
override public function update():Void
{
super.update();
- if (_index < _curve.length - 1)
+ var td:Float;
+ var tt:Float;
+
+ if (!_backward)
{
- while (_t > _curveT[_index + 1]) _index ++;
+ if (_index < _curve.length - 1)
+ {
+ while (_t > _curveT[_index + 1]) _index++;
+ }
+ td = _curveT[_index];
+ tt = _curveT[_index + 1] - td;
+ td = (_t - td) / tt;
+ _a = _curve[_index];
+ _b = _points[_index + 1];
+ _c = _curve[_index + 1];
+ x = _a.x * (1 - td) * (1 - td) + _b.x * 2 * (1 - td) * td + _c.x * td * td;
+ y = _a.y * (1 - td) * (1 - td) + _b.y * 2 * (1 - td) * td + _c.y * td * td;
}
- var td:Float = _curveT[_index],
- tt:Float = _curveT[_index + 1] - td;
- td = (_t - td) / tt;
- _a = _curve[_index];
- _b = _points[_index + 1];
- _c = _curve[_index + 1];
- x = _a.x * (1 - td) * (1 - td) + _b.x * 2 * (1 - td) * td + _c.x * td * td;
- y = _a.y * (1 - td) * (1 - td) + _b.y * 2 * (1 - td) * td + _c.y * td * td;
+ else
+ {
+ if (_index > 0)
+ {
+ while (_t < _curveT[_index - 1])
+ {
+ _index -= 1;
+ }
+ }
+
+ td = _curveT[_index];
+ tt = _curveT[_index - 1] - td;
+ td = (_t - td) / tt;
+ _a = _curve[_index];
+ _b = _points[_index];
+ _c = _curve[_index - 1];
+ x = _a.x * (1 - td) * (1 - td) + _b.x * 2 * (1 - td) * td + _c.x * td * td;
+ y = _a.y * (1 - td) * (1 - td) + _b.y * 2 * (1 - td) * td + _c.y * td * td;
+ }
+
+ super.postUpdate();
}
/** @private Updates the path, preparing the curve. */
@@ -121,15 +168,15 @@ class QuadPath extends Motion
_updateCurve = false;
// produce the curve points
- var p:Point,
- c:Point,
- l:Point = _points[1],
+ var p:FlxPoint,
+ c:FlxPoint,
+ l:FlxPoint = _points[1],
i:Int = 2;
while (i < _points.length)
{
p = _points[i];
if (_curve.length > i - 1) c = _curve[i - 1];
- else c = _curve[i - 1] = new Point();
+ else c = _curve[i - 1] = new FlxPoint();
if (i < _points.length - 1)
{
c.x = l.x + (p.x - l.x) / 2;
@@ -171,10 +218,10 @@ class QuadPath extends Motion
private function getPointCount():Float { return _points.length; }
/** @private Calculates the lenght of the curve. */
- private function curveLength(start:Point, control:Point, finish:Point):Float
+ private function curveLength(start:FlxPoint, control:FlxPoint, finish:FlxPoint):Float
{
- var a:Point = HXP.point,
- b:Point = HXP.point2;
+ var a:FlxPoint = QuadPath._Point,
+ b:FlxPoint = QuadPath._Point2;
a.x = start.x - 2 * control.x + finish.x;
a.y = start.y - 2 * control.y + finish.y;
b.x = 2 * control.x - 2 * start.x;
@@ -191,19 +238,22 @@ class QuadPath extends Motion
}
// Path information.
- private var _points:Array<Point>;
+ private var _points:Array<FlxPoint>;
private var _distance:Float;
private var _speed:Float;
private var _index:Int;
// Curve information.
private var _updateCurve:Bool;
- private var _curve:Array<Point>;
+ private var _curve:Array<FlxPoint>;
private var _curveT:Array<Float>;
private var _curveD:Array<Float>;
// Curve points.
- private var _a:Point;
- private var _b:Point;
- private var _c:Point;
+ private var _a:FlxPoint;
+ private var _b:FlxPoint;
+ private var _c:FlxPoint;
+
+ private static var _Point:FlxPoint = new FlxPoint();
+ private static var _Point2:FlxPoint = new FlxPoint();
}
View
8 src/org/flixel/tweens/sound/SfxFader.hx
@@ -22,6 +22,14 @@ class SfxFader extends FlxTween
_complete = complete;
_sfx = sfx;
}
+
+ override public function destroy():Void
+ {
+ super.destroy();
+ _sfx = null;
+ _crossSfx = null;
+ _complete = null;
+ }
/**
* Fades the Sfx to the target volume.
Please sign in to comment.
Something went wrong with that request. Please try again.