Chapter 9. Adding Social Media and Other Online Services

Modern mobile devices are now amazingly powerful when it comes to graphics and sound, but perhaps the biggest differentiator between them and other dedicated hand-held videogame systems is that most of them are able to connect to the Internet.

While other gaming systems may be able to go online via WiFi, many modern devices can also use a 3G or other such data connections to connect to the Internet wherever the user happens to be. For this reason many games now feature the ability to connect to social media sites such as Facebook, or to share scores using services such as Apple's Game Center.

In this chapter, we will be looking at how it is possible to use Marmalade to add the following online capabilities to our games:

  • Launching a web browser to display a web page
  • Integrating with Facebook on iOS and Android
  • Familiarizing ourselves with the possibilities for other online functionality, including advertising and in-app purchasing

Launching a web page in the device browser

Let's start our foray into the realm of the connected world by looking at the simplest way of adding an online feature to our games—launching a web page in the device browser.

Being able to direct the user to a website can be extremely useful for things such as instruction manuals, hints and tips, or technical support access. It is also great for cross promotion of titles by making it really simple to deliver a Get More Games button that highlights other games you have created.

How do we accomplish this magic? It's really simple! Just include the header file s3eOSExec.h and then make a call to s3eOSExecAvailable to see if the functionality is supported by the platform we are running on. Most of the platforms supported by Marmalade allow this functionality, but it is always best to check!

If support is available, all we have to do is call the function s3eOSExecExecute with the URL of the web page and a Boolean value indicating whether or not our application will quit. On platforms that don't support multi-tasking this parameter will make no difference, so it is usually OK to set this flag to false to ensure that our application is not closed down.

Here's a code snippet to illustrate:

if (s3eOSExecAvailable())
{
  s3eOSExecExecute("http://www.google.com", false);
}

The main disadvantage of this approach is that by launching the application in the device's internal web browser, it takes the user away from our game; but in the cases mentioned previously, this may be an acceptable trade-off given how easy it is to implement.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.3.167