Permalink
Browse files

Change Motion tween to have a "object" property.

The x and y values computed by the Tween will be automatically applied to the
object's x and y properties too. The object can have any type, as long as it
allows assignment to its x and y properties (so instances of Entity, Point,
or Image will all work). The change is backwards compatible, and can be used
as before regardless of whether the object is set.
  • Loading branch information...
1 parent 1c70f06 commit 243a5aa075161154c79793069c080aa75fa5a4f1 @BlckKnght BlckKnght committed Apr 30, 2012
Showing with 32 additions and 2 deletions.
  1. +32 −2 net/flashpunk/tweens/motion/Motion.as
@@ -10,12 +10,38 @@
/**
* Current x position of the Tween.
*/
- public var x:Number = 0;
+ public function get x():Number { return _x; }
+ public function set x(value:Number):void
+ {
+ _x = value;
+ if (_object)
+ _object.x = _x;
+ }
/**
* Current y position of the Tween.
*/
- public var y:Number = 0;
+ public function get y():Number { return _y; }
+ public function set y(value:Number):void
+ {
+ _y = value;
+ if (_object)
+ _object.y = _y;
+ }
+
+ /**
+ * Target object for the tween. Must have an x and a y property.
+ */
+ public function get object():Object { return _object; }
+ public function set object(value:Object):void
+ {
+ _object = value;
+ if (_object)
+ {
+ _object.x = _x;
+ _object.y = _y;
+ }
+ }
/**
* Constructor.
@@ -28,5 +54,9 @@
{
super(duration, type, complete, ease);
}
+
+ protected var _x:Number = 0;
+ protected var _y:Number = 0;
+ protected var _object:Object;
}
}

0 comments on commit 243a5aa

Please sign in to comment.