public void Scroll(float duration) { Roga2dPositionInterval posInterval = new Roga2dPositionInterval(this, new Vector2(0, 0), Roga2dUtils.pixelToLocal(new Vector2(320, 0)), Roga2dUtils.TimeToFrame(duration), true, null); Roga2dFunc func = new Roga2dFunc(this.onScrolled); Roga2dBaseInterval interval = new Roga2dSequence(new List<Roga2dBaseInterval> {posInterval, func}); Roga2dIntervalPlayer.GetInstance().Play(interval); }
public static void TestTween() { Roga2dNode node = new Roga2dNode(); Roga2dAlphaInterval interval1 = new Roga2dAlphaInterval(node, 0.1f, 1.0f, 3, true); Roga2dWait interval2 = new Roga2dWait(2); Roga2dAlphaInterval interval3 = new Roga2dAlphaInterval(node, 0.7f, 0.0f, 2, true); List<Roga2dBaseInterval> intervals = new List<Roga2dBaseInterval>(); intervals.Add(interval1); intervals.Add(interval2); intervals.Add(interval3); Roga2dSequence sequence = new Roga2dSequence(intervals); sequence.Start(); Tester.Match(node.LocalAlpha, 0.1f); Tester.Ok(!sequence.IsDone()); sequence.Update(); Tester.Match(node.LocalAlpha, 0.4f); Tester.Ok(!sequence.IsDone()); sequence.Update(); Tester.Match(node.LocalAlpha, 0.7f); Tester.Ok(!sequence.IsDone()); sequence.Update(); Tester.Match(node.LocalAlpha, 1.0f); Tester.Ok(!sequence.IsDone()); sequence.Update(); Tester.Match(node.LocalAlpha, 1.0f); Tester.Ok(!sequence.IsDone()); sequence.Update(); Tester.Match(node.LocalAlpha, 1.0f); Tester.Ok(!sequence.IsDone()); sequence.Update(); Tester.Match(node.LocalAlpha, 0.35f); Tester.Ok(!sequence.IsDone()); sequence.Update(); Tester.Match(node.LocalAlpha, 0.0f); Tester.Ok(sequence.IsDone()); sequence.Reset(); Tester.Match(node.LocalAlpha, 0.1f); Tester.Ok(!sequence.IsDone()); node.Destroy(); }
public static void TestFuncSequence() { i = 0; List<Roga2dBaseInterval> intervals = new List<Roga2dBaseInterval>() { new Roga2dFunc(callback), new Roga2dFunc(callback), new Roga2dFunc(callback) }; Roga2dSequence interval = new Roga2dSequence(intervals); interval.Update(); Tester.Match(i, 3); Tester.Ok(interval.IsDone()); }
public static void Test2Loop() { Roga2dNode node = new Roga2dNode(); Roga2dAlphaInterval interval1 = new Roga2dAlphaInterval(node, 0.1f, 1.0f, 1, true); Roga2dWait interval2 = new Roga2dWait(1); Roga2dAlphaInterval interval3 = new Roga2dAlphaInterval(node, 0.7f, 0.0f, 1, true); List<Roga2dBaseInterval> intervals = new List<Roga2dBaseInterval>(); intervals.Add(interval1); intervals.Add(interval2); intervals.Add(interval3); Roga2dSequence sequence = new Roga2dSequence(intervals); Roga2dLoop loop = new Roga2dLoop(sequence, 2); loop.Start(); Tester.Match(node.LocalAlpha, 0.1f); Tester.Ok(!loop.IsDone()); loop.Update(); Tester.Match(node.LocalAlpha, 1.0f); Tester.Ok(!loop.IsDone()); loop.Update(); Tester.Match(node.LocalAlpha, 1.0f); Tester.Ok(!loop.IsDone()); loop.Update(); Tester.Match(node.LocalAlpha, 0.1f); Tester.Ok(!loop.IsDone()); loop.Update(); Tester.Match(node.LocalAlpha, 1.0f); Tester.Ok(!loop.IsDone()); loop.Update(); Tester.Match(node.LocalAlpha, 1.0f); Tester.Ok(!loop.IsDone()); loop.Update(); Tester.Match(node.LocalAlpha, 0.0f); Tester.Ok(loop.IsDone()); node.Destroy(); }
// Build animation for damage pop public Roga2dAnimation BuildDamagePopAnimation(Vector2 position, uint value) { Roga2dNode node = new Roga2dNode("Damage"); List<uint> digits = Utils.getDigits(value); position.x -= (10 * digits.Count) / 2; node.LocalPixelPosition = position; node.LocalPriority = 1.0f; List<Roga2dBaseInterval> popIntervals = new List<Roga2dBaseInterval>(); for (int i = 0; i < digits.Count; i++) { uint no = digits[i]; // Get Font Image Roga2dSprite sprite = new Roga2dSprite("Font/number_font", new Vector2(7, 10), new Vector2(0, 0), new Rect(no * 7, 0, 7, 10)); // X-coordinate each digit pop int popX = i * 10; // Init state sprite.LocalAlpha = 0.0f; sprite.LocalPosition = Roga2dUtils.pixelToLocal(new Vector2(popX, 0)); // Add to parent node.AddChild(sprite); Roga2dBaseInterval interval = new Roga2dSequence( new List<Roga2dBaseInterval>() { new Roga2dWait(Roga2dUtils.TimeToFrame(i * 0.05f)), new Roga2dAlphaInterval(sprite, 1.0f, 1.0f, Roga2dUtils.TimeToFrame(0.05f), false), new Roga2dPositionInterval(sprite, Roga2dUtils.pixelToLocal(new Vector2(popX, 0)), Roga2dUtils.pixelToLocal(new Vector2(popX, -30)), Roga2dUtils.TimeToFrame(0.1f), true, null) // TODO: destroy damage effects } ); popIntervals.Add(interval); } Roga2dBaseInterval resultInterval = new Roga2dSequence(new List<Roga2dBaseInterval>() { new Roga2dParallel(popIntervals), new Roga2dWait(5) }); return Roga2dAnimation.Build(node, resultInterval); }
public static void TestMixTween() { Roga2dNode node = new Roga2dNode(); Roga2dAlphaInterval interval1 = new Roga2dAlphaInterval(node, 1.0f, 0.5f, 1, false); Roga2dAlphaInterval interval2 = new Roga2dAlphaInterval(node, 0.5f, 0.3f, 1, false); Roga2dAlphaInterval interval3 = new Roga2dAlphaInterval(node, 0.3f, 0.1f, 1, true); Roga2dAlphaInterval interval4 = new Roga2dAlphaInterval(node, 0.1f, 0.1f, 1, true); List<Roga2dBaseInterval> intervals = new List<Roga2dBaseInterval>(); intervals.Add(interval1); intervals.Add(interval2); intervals.Add(interval3); intervals.Add(interval4); Roga2dSequence sequence = new Roga2dSequence(intervals); sequence.Start(); Tester.Match(node.LocalAlpha, 1.0f); Tester.Ok(!sequence.IsDone()); sequence.Update(); Tester.Match(node.LocalAlpha, 0.5f); Tester.Ok(!sequence.IsDone()); sequence.Update(); Tester.Match(node.LocalAlpha, 0.3f); Tester.Ok(!sequence.IsDone()); sequence.Update(); Tester.Match(node.LocalAlpha, 0.1f); Tester.Ok(!sequence.IsDone()); sequence.Update(); Tester.Match(node.LocalAlpha, 0.1f); Tester.Ok(sequence.IsDone()); node.Destroy(); }
public void OnStepMoved(StepData step, float duration) { Vector2 piecePixelPos = this.playerPiece.LocalPixelPosition; Vector2 piecePos = Roga2dUtils.pixelToLocal(new Vector2(piecePixelPos.x, piecePixelPos.y)); Vector2 movePos = Roga2dUtils.pixelToLocal(new Vector2(step.PosX + 16, step.PosY + 16)); Vector2 cameraPos = this.camera.LocalPosition; Vector2 cameraFocusPos = Roga2dUtils.pixelToLocal(new Vector2(piecePixelPos.x - 16, piecePixelPos.y - 16)); Vector2 cameraMovePos = Roga2dUtils.pixelToLocal(new Vector2(step.PosX , step.PosY)); Roga2dFunc func = new Roga2dFunc(this.onPieceMoved); // Move camera and piece at the same time Roga2dParallel parallel = new Roga2dParallel(new List<Roga2dBaseInterval> { new Roga2dPositionInterval(this.playerPiece, piecePos, movePos, Roga2dUtils.TimeToFrame(duration), true, null), new Roga2dPositionInterval(this.camera, cameraFocusPos, cameraMovePos, Roga2dUtils.TimeToFrame(duration), true, null) }); // At first move back to the piece position float distance = Vector2.Distance(cameraPos, piecePos); float cameraFocusDuration = distance * 0.2f; Roga2dSequence sequence = new Roga2dSequence(new List<Roga2dBaseInterval> { new Roga2dPositionInterval(this.camera, cameraPos, cameraFocusPos, Roga2dUtils.TimeToFrame(cameraFocusDuration), true, null), parallel, func }); Roga2dIntervalPlayer.GetInstance().Play(sequence); }