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 TestFunc() { Roga2dFunc interval = new Roga2dFunc(callback); i = 0; Tester.Ok(!interval.IsDone()); interval.Update(); Tester.Match(i, 1); Tester.Ok(interval.IsDone()); interval.Update(); Tester.Match(i, 1); Tester.Ok(interval.IsDone()); }
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); }