// game loop... 120fps private void Timer_Tick(object sender, object e) { if (UpPressed) { butterfly.Move(); } // rotate if (LeftPressed) { butterfly.Rotate(-1); // -1 == left } if (RightPressed) { butterfly.Rotate(1); // 1 == right } // collision... flower. CheckCollision(); //update butterfly.UpdatePosition(); }
public MainPage() { this.InitializeComponent(); // windows size 800*600 ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize; ApplicationView.PreferredLaunchViewSize = new Size(800, 600); // get Canvas size CanvasWidth = MyCanvas.Width -150; CanvasHeight = MyCanvas.Height -132; // add butterfly butterfly = new Butterfly { LocationX = CanvasWidth/2, LocationY = CanvasHeight/2 }; MyCanvas.Children.Add(butterfly); butterfly.UpdatePosition(); //add flower AddFlower(); //Load Audio LoadAudio(); // key listeners Window.Current.CoreWindow.KeyDown += CoreWindow_KeyDown; Window.Current.CoreWindow.KeyUp += CoreWindow_KeyUp; // initialize game loop timer = new DispatcherTimer(); timer.Tick += Timer_Tick; timer.Interval = new TimeSpan(0, 0, 0, 0, 1000/120); //try 120fps timer.Start(); }
public MainPage() { this.InitializeComponent(); // windows size 800*600 ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize; ApplicationView.PreferredLaunchViewSize = new Size(800, 600); // get Canvas size CanvasWidth = MyCanvas.Width - 150; CanvasHeight = MyCanvas.Height - 132; // add butterfly butterfly = new Butterfly { LocationX = CanvasWidth / 2, LocationY = CanvasHeight / 2 }; MyCanvas.Children.Add(butterfly); butterfly.UpdatePosition(); //add flower AddFlower(); //Load Audio LoadAudio(); // key listeners Window.Current.CoreWindow.KeyDown += CoreWindow_KeyDown; Window.Current.CoreWindow.KeyUp += CoreWindow_KeyUp; // initialize game loop timer = new DispatcherTimer(); timer.Tick += Timer_Tick; timer.Interval = new TimeSpan(0, 0, 0, 0, 1000 / 120); //try 120fps timer.Start(); }