UrhoSharp is a lightweight Game Engine suitable for using with C# and F# to create games that run on Android, iOS, Mac, Windows and Unix. The game engine is available as a portable class library, allowing your game code to be written once and shared across all platforms. UrhoSharp is powered by Urho3D (http://urho3d.github.io/), a game engine that has been under development for more than a decade.The idea is the same as Xamarin: you write your code once and your app will run on many different platforms. In this case:
Windows (WPF and UWP so it will run also on Windows phones)
After several months of silence UrhoSharp has come back strongly with a new release (v.1.8.91) tha fixes many bugs and updates this extremely powerful engine.The biggest news are:
Updated to Urho3D 1.7
ARKit and ARCore components
Fixed major Android and iOS crashes
Optional DirectX11 backend for Windows
UWP 64bit support (and .NET Native toolchain)
The amazing thing is that with UrhoSharp you can create your 2D/3D games and also create amazing Augmented Reality apps thanks to support to ARKit (iOS) and ARCore (Android).
I’m writing a tutorial on how to use UrhoSharp and I’ll publish it here as soon as it ready.
To help you to speed up your Xamarin development, I’ve created a set of plugins, one of them is MTAdmob. Thanks to this plugin you can add Admob banners and Insterstitials in just few lines of code. It couldn’t be easier than that and I’ll show you.
Install the plugin
First of all, right click on your Xamarin solution and select “Manage Nuget packages for Solution”
Visual Studio will open a new screen where you can search and install one or more nuget packages. In this case we can search for the MTAdmob plugin. Searching for MarcTron will show you all my packages (I’m sure you can find other useful plugins that I’ve written), and we can select the MTAdmob plugin as showed in the next image.
It’s very important that you install the plugin in your PCL/.Net standard project and in your platform projects (Android, iOS, UWP).
After the Admob plugin is installed we can add banners and insterstitials to our projects.
Add Ads to our project
With version 1.0 the MTAdmob plugin supports banner and interstitials for Android and iOS. If you would like to see the plugin supporting also the UWP platform, let me now and I’ll add the support in a new version.
As I’ve said we can add Banners and Interstitials Admob ads to our project. Let’s start with the Banners
How to add an Admob Banner
An Admob banner is just a view inside our page. It means that we can add it using XAML or C#. First of all let’s see how to add an Admob banner using XAML.
Add an Admob Banner with XAML
In MTAdmob to use an Admob banner I’ve created a custom control called AdView, so to use it we can use this code:
<?xml version="1.0" encoding="utf-8" ?>
<Label Text="Let's test an Admob Banner!"
<!-- Place the Admob controls here -->
In this example we have created a StackLayout with 2 controls: a label and an AdView (our Admob banner). Easy! Isn’t it???
The AdView control is basically a View so you can use all the properties you can think of like: HorizontalOptions, VerticalOptions, IsVisible…
In addition to these properties, I’ve added in AdView two other properties: AdsId and PersonalizedAds.
AdsId: Allows you to add the Banner Id (you can find it in your Admob account)
PersonalizedAds: This allow you to use non personalized ads. For example in case of GPDR. Of course it’s better to use personalized Ads.
To use these properties you can update the previous code to:
Of course you can use these events also if you have declared your AdView in your XAML code.
Now that we know how to add Admob banners using my plugin MTAdmob, let’s see how we can add Admob Interstitials. If possible, to add an Admob interstitial is even easier. You just need a single line of code. Don’t you believe me? Look here how to show an Admob interstitial:
I told you!!! That’s it!!! With that line of code you have just showed an Interstitial in you app. Of course you need to replace that string with the Insterstitial ID you can find in your Admob account.
Events for Interstitials
There 3 events that you can use with Interstitials:
OnInterstitialLoaded When it's loaded
OnInterstitialOpened When it's opened
OnInterstitialClosed When it's closed
From version 1.1 the plugin supports the amazing Rewarded Video too.
To show a rewarded video you just need a single line of code:
There are 7 events that you can use with the Rewarded video Ads:
OnRewarded When the user gets a reward
OnRewardedVideoAdClosed When the ads is closed
OnRewardedVideoAdFailedToLoad When the ads fails to load
OnRewardedVideoAdLeftApplication When the users leaves the application
OnRewardedVideoAdLoaded When the ads is loaded
OnRewardedVideoAdOpened When the ads is opened
OnRewardedVideoStarted When the ads starts
Before you can use the Admob banners and Interstitials, you need to initialize it. You need to do it only once so it makes sense to initialize it onside the OnCreate method in Android and FinishedLaunching in iOS.
In your Android project add this line in your OnCreate method:
Xamarin has a long story of problematic releases where new features comes along with numerous bugs.For this reason is possible that you are still using an old version of Xamarin.Forms.But today you will see why you should really upgrade to Xamarin.Forms 2.5
Sometimes to create the UI we want, we need to add several layouts that are not visible but are needed as container for other components.As you can imagine, all these layouts come with a cost and you can see it especially on older Android devices.Layout compression helps us to solve this problem reducing the number of views to render.Consider this basic example:
We have a StackLayout that contains two buttons, the only reason to have this layout is to add the two buttons at the same height.Even if we don’t see the layout, having it in our Page has a cost.With the Layout Compression we can keep the StackLayout and remove its cost.To enable the compression of the StackLayout we need to add the codeCompressedLayout.IsHeadless="true"so the previous example will be:
Easy. Isn’t it? You can enable the Layout compression on: StackLayout, AbsoluteLayout, Grid, RelativeLayout.Because the compression removes the renderer for the layout, candidates for the compression are layouts that don’t have:
Layout Compression is available on iOS and Android.
Ok this is not entirely a new feature (they arrived on Xamarin.Forms 2.4) but it’s definitely a feature you shouldn’t miss.We love Xamarin but we also know that sometimes, especially on Android the performances are not really amazing.Fast Renderers for Android will improve performances on your Xamarin.Forms applications.As this is still an experimental feature, to enable them you need to add this line
to your MainActivity class before calling Forms.Init
I’ve personally tested Layout compression and Fast Renderers and I can confirm that there is a performance improvement especially on older Android devices so I really suggest you to use these features in your projects.
I have to tell you, I’m not particularly inclined to mix things so I prefer to keep separated Xamarin.Forms and native Xamarin projects.BUT…I can honestly see cases where you already have existing Xamarin.Forms pages and you want to use in other Xamarin iOS, Android or UWP projects.Thanks to the Forms Embedding now you can do it.
Improved macOS Desktop Support
In case you want to add macOS desktop support in your Xamarin.Forms apps 🙂
As you know is very important to keep your system updated and this of course is valid for the Android SDK.You should alway use the lasted available Android components.The Official Xamarin Documentation is not very clear on how to configure properly the Android SDK, so here is what you should do to obtain the best from your Xamarin.Android projects.First of all you should really install the Xamarin Android SDK Manager instead of the classic SDK Manager.Probably the most important reason to do so is that since version 25.2.3 of the Android SDK Tools package, Google replaced the UI Manager with a command line utility. I really don’t know why, but I know that the Xamarin Android SDK Manager is a very good tool. So I really suggest you to download it.As stated in the official Xamarin website, the requirements are:
Visual Studio 2017 community edition or higher. Visual Studio 2017 version 15.5 or later is required. (I’ll suggest you to use the latest version 15.6)
The Xamarin Android SDK Manager is not compatible with Visual Studio 2015. You can add the Xamarin SDK Manager using the Visual Studio Installer:
Be sure to select the Xamarin SDK Manager and install it.If you launch again Visual Studio 2017 and click on Tools > Android > Android SDK Manager, the Xamarin Android SDK Manager will be launched instead of the Google Android SDK Manager.
Here there are two tabs: Platforms and Tools.
Inside the first Tab you can download and install the platforms you want to support. You don’t need to install all the platforms, you just need to install the most recent one and the lowest that you still want to support.So if you want to support the platforms from Android 4.1, just install the Android SDK Platform 16 (Android 4.1) and the Android SDK Platform 16 (Android Oreo 8.1).
From the Tools Tab, you should always try to update the tools to the latest version:
So you should install:
Android SDK Tools 26.1.1
Android SDK Platform-Tools 27.0.1
Android SDK Build-Tools 27.0.3
I also suggest you to install the Android emulator is case you want to try your app on multiple devices. The latest available version is:
Android Emulator 27.1.12
I’ll update this guide every time there will be an updated component so I suggest to bookmark/follow this page.