0

i want to ask if i want to create agame loop for controling motion in my 2D Silverlight game ( sample game like snake) which will run on Windows Phone , what is the best practice to do this ? i found different methods used: 1- CompositionTarget.Render(). 2- Dispatcher Timer. 3- stroy board.

which is more suitable for creating sample game loop ?

Ahmed Emad
  • 550
  • 2
  • 7
  • 25

2 Answers2

0

The XNA's game loop on Windows Phone is based on Silverlight's Dispatcher Timer. So it's definitely suitable for this kind of purpose.

Kevin Gosse
  • 38,392
  • 3
  • 78
  • 94
0

Out of your methods listed, DIspatcher Timer is the best method for creating a game loop.

HOWEVER, I strongly encourage you not to use Silverlight and instead use the XNA API if you want to create a game, even for simple games like Snake its much easier to program a game with game architecture, Silverlight is designed for Event-Driven Applications (normal apps) and XNA is designed specifically with games in mind (Update Logic, then Drawing 2D or 3D images on the GPU). Also, if you stick with silverlight unless you use storyboards that make use of the composition thread, none of your drawing will be hardware-accelerated and will really slow down the performance of your application.

Also, if you target Windows Phone 8 specifically you can create a Direct3D app and use the DirectX Toolkit to get the "xna" spritebatch class in C++. A game loop and 2D drawing code will be automatically setup for you using that method.

Strifex
  • 832
  • 1
  • 7
  • 16
  • thanks for your help Strife but i will target Windows phone 8 so i can't use XNA and forced to search for solution with silverlight so i searched for the optimal solution to create it and as i understood you recommend using dispatcher timer – Ahmed Emad Feb 05 '13 at 07:06
  • The most optimal method would still be to switch to C++ and make a "Direct3D" application for Windows Phone 8. Then you could use the DirectX Toolkit (Microsoft open-source library) to draw .dds images with their spritebatch class. This allows your application to have incredible performance as its all native code, efficient .dds textures as your images, and you avoid having the garbage collector bog down your game loop. – Strifex Feb 06 '13 at 05:36