Johan Karlsson: Enabling multitouch using CocosSharp
Short version
Long version
I’ve started a little secret project of my own that required two things:
- A simple framework for drawing stuff
- A simple input scheme for multitouch
So I checked out the available frameworks out there for Xamarin (especially for Xamarin Forms) and I decided to give CocosSharp a run for its money. I’ve done some small CocosSharp projects before and it fits my needs for the prototyping of this app.
I’m using the Forms version of CocosSharp since I’m a big Xamarin Forms fan.
The issue
One of the first things I noticed was that the multitouch simply didn’t work as I expected. No matter what properties I set there was no multitouch going on. After some google-fu I found out that you have to set the MultipleTouchEnabled to true on the CCGameView instance. Well, the CCGameView is platform specific and there is no exposure of this property in the platform agnostic CocosSharpView that you use in the forms project.
Custom renderer to the rescue
{
base.OnElementChanged (e);
if (Control != null) {
Control.MultipleTouchEnabled = true;
}
}
That didn’t work. In fact, the method is never called. (Yes, I registered the renderer! 🙂 ).
Create a custom control (the work around)
{
}