Johan Karlsson: Enabling multitouch using CocosSharp

It’s been a long time since my last blog post due to personal and professional reasons. Anyhow, now I’m planning to get back in the saddle and start blogging on a regular basis again. Also, this happens to be blog post number 100. Yay!

Short version

To enable multitouch in CocosSharp (Forms version) you must create a custom renderer to set the MultipleTouchEnabled on the CCGameView (platform specific code) and then you must inherit from the CocosSharpView in order to make the registration of the custom renderer work. Code in the bottom of the post.

Long version

I’ve started a little secret project of my own that required two things:

  1. A simple framework for drawing stuff
  2. 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

Well, that’s a simple fix I figured. Simply create a custom renderer and set the property directly.
    protected override void OnElementChanged (ElementChangedEventArgs<CocosSharpView> e)
    {
        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)

So the simple work around for this was to create a custom control.
    public class MyCocosSharpView : CocosSharpView 
    {
    }
And then use MyCocosSharpView instead of CocosSharpView. I’m not sure why it behaves this way, but its got to have something to do with the registration of the custom renderer. Hopefully I’ll get some time to drill down in the source code and find out why.

What I would like

The MultpleTouchEnabled property should be visible from the CocosSharpView class. That is at least what I’ll suggest to the CocosSharp team.

The code

These are the interesting parts of the code. 
Details

Adam J Wolf: Weekly Xamarin Newsletter Issue #90

Live From Evolve Open Source Xamarin, Ready for you! Miguel de Icaza officially announces the open sourcing of Xamarin. Faster and Easier Mobile App Development with Xamarin.Forms Jason Smith wants to make you even more productive with Xamarin.Forms. The New, Mobile-Optimized Development Lifecycle Keith Ballinger announces the modernization of mobile DevOps. Browse Through the Evolve […]

The post Weekly Xamarin Newsletter Issue #90 appeared first on Syntax is my UI.

Details

Greg Shackles: Pressure Is On with 3D Touch in iOS Apps

With the release of the iPhone 6S and 6S Plus, together with the iOS 9 operating system, Apple introduced 3D Touch. What it allows is the addition of pressure-based interactions into your apps, which can be added in a variety of ways.

In this article I’ll introduce a couple built-in standard 3D Touch interaction models, but iOS also provides a direct API to the pressure sensors, allowing you to leverage the data in any way that makes sense in your apps.

Continue reading the rest of the article over at Visual Studio Magazine

Details