We had a play with the new glossy leap motion gadget at the first Factory forty Open hack of the history. This kittle tiny kinnect brother open to Mac and PC users a new way to interact with application. This tutorial show how to setup a MonoGame project with Leap motion SDK on Monodevelop and create a small App (Mac on our Tutorial but principle is the same on PC) which explain the basics and open field of opportunities for monogame developers.
In our case we prefer use Monodevelop (3.0.x) rather than Xamarin (4.0.x) because we had several issue using Monogame framework with it. You can down monodevelop 3.0.8 on sourceforge website here. For Xamarin master who knows tricks to make work monogame on there so loved editors don’t hesitate to share it in a comment.
Let’s install the libraries, you can get monogame mpack here and install it to monodevelop. After that you can get LeapMotion SDK by subscribing to the developer program here, there is no mpack file but some dll will be added to the solution later on.
Configure the project
We’ll start creating a solution for a monogame application (Mac on our example)
We’ll make a new folder in our project directory call lib and copy the LeapMotion C# dll file from the SDK into it (your_download_directory/LeapSDK/lib/LeapCSharp.NET4.0.dll -> your_project/lib).
On project references directory we’ll add the dll file (Right click on References directory, modify references), We’ll click on “.Net Assembly” tab, go to your_project_directory/lib, select LeapCSharp.NET4.0.dll and click Add. You will see on your references directory your new LeapCSharp.NET4.0.dll.
We’ll add libLeapCSharp.dylib and libLeap.dylib from the SDK (your_download_directory/LeapSDK/lib directory) into the project content directory. We’ll select the two file and set there building actions to BundleRessource (right click -> bundle action). We’ll change bundle action of logo.png to Content. This means these three files we’ll be packed inside you app each time you build it and then make it accessible to your program.
Here is what you should see in your solution panel. In my example I also add the monogame dll directly by coping them to the lib directory and add the assemblies manually the same way explained for Leap Motion dll
Now solution is up and ready you can save it as template and just copy it when you make a new project .
We’ll first create LeapListener Class. This class extends Leap listener class which is used to listen to Leap motion events and provide leap motion tracking data. Our Class will take all these data calculate (with Leap motion screen class) the projection of your finger position to the screen (it will guess where your finger is pointing to the screen) and store it in a coordinate collection.
We’ll now modify the Game1 class (generated by monogame application solution template) in order to initialize LeapMotion controller and LeapListener Class, get finger point data and display sprites at the right position.
Now you can build you app and enjoy the magic of leap motion with the simplicity of monogame.
Don’t hesitate to ask if you have any question or suggestion to make this tutorial better and up to date.