1 using Tizen.NUI.BaseComponents;
2 using Tizen.NUI.Extension;
3 using Tizen.NUI.Components;
5 namespace Tizen.NUI.Samples
7 public class RiveAnimationFollowTouch : IExample
10 private Layer defaultLayer;
12 Tizen.NUI.Extension.RiveAnimationView rav;
13 Button playButton, stopButton;
14 Button bounceButton, brokeButton;
15 Button fillButton, strokeButton, opacityButton;
16 Button scaleButton, rotationButton, positionButton;
17 public void Activate()
19 window = NUIApplication.GetDefaultWindow();
20 defaultLayer = window.GetDefaultLayer();
21 window.TouchEvent += OnRiveWindowTouchEvent;
23 // Load RiveAnimation File
24 rav = new Tizen.NUI.Extension.RiveAnimationView(Tizen.Applications.Application.Current.DirectoryInfo.Resource + "rive/flame-and-spark.riv")
26 Size = new Size(720, 720),
29 // Enable RiveAnimation and Play
30 rav.EnableAnimation("idle", true);
33 playButton = new Button()
35 Size = new Size(200, 100),
36 Position = new Position(0, 0),
39 playButton.Clicked += (object source, ClickedEventArgs args) =>
44 defaultLayer.Add(rav);
45 defaultLayer.Add(playButton);
48 private void OnRiveWindowTouchEvent(object source, Window.TouchEventArgs e)
50 Vector2 lp = e.Touch.GetLocalPosition(0);
51 Vector2 sp = e.Touch.GetScreenPosition(0);
52 float scale = (1000.0f /720.0f);
54 // Set root and spark node position
55 rav.SetNodePosition("root", new Position(lp.X * scale, lp.Y * scale));
56 rav.SetNodePosition("spark", new Position((lp.X - 288) * scale, lp.Y) * scale);
58 public void Deactivate()
60 defaultLayer.Remove(rav);
61 defaultLayer.Remove(playButton);