Effects/LayerMover.cpp

changeset 1
1ef17765f966
child 20
cc549c0f8ebd
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Effects/LayerMover.cpp	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,58 @@
+#include "LayerMover.h"
+
+namespace geffects {
+	void LayerMover::Setup(Point From, Point To, int Time) {
+
+		from=From;
+		current=from;
+		to=To;
+
+		Target->X=from.x;
+		Target->Y=from.y;
+		this->progressed=0;
+
+		if(Time) {
+			speed.x=(float)(to.x-from.x)/Time;
+			speed.y=(float)(to.y-from.y)/Time;
+			this->Play();
+		} else {
+			speed.x=0;
+			speed.y=0;
+			current=from=to;
+			Target->X=to.x;
+			Target->Y=to.y;
+		}
+	}
+
+	bool LayerMover::isFinished() {
+		return current.x==to.x && current.y==to.y;
+	}
+
+	void LayerMover::Process(int Time) {
+		if(from.x>to.x) {
+			current.x=from.x+Time*speed.x;
+
+			if(current.x<to.x)
+				current.x=to.x;
+		} else {
+			current.x=from.x+Time*speed.x;
+			if(current.x>to.x)
+				current.x=to.x;
+		}
+		Target->X=current.x;
+
+
+		if(from.y>to.y) {
+			current.y=from.y+Time*speed.y;
+
+			if(current.y<to.y)
+				current.y=to.y;
+		} else {
+			current.y=from.y+Time*speed.y;
+			if(current.y>to.y)
+				current.y=to.y;
+		}
+		Target->Y=current.y;
+
+	}
+}
\ No newline at end of file

mercurial