Reader small image

You're reading from  Corona SDK Mobile Game Development: Beginner's Guide

Product typeBook
Published inMar 2015
Publisher
ISBN-139781783559343
Edition1st Edition
Tools
Right arrow
Author (1)
Michelle M Fernandez
Michelle M Fernandez
Right arrow

Chapter 9. Handling Multiple Devices and Networking Your Apps

Allowing your application to integrate with social networks is a great way to promote your finished product. Many games enable the player to upload their high scores and share them among other users who are playing the same title. Some provide challenges that need to be completed successfully in order to unlock achievements. Social networks enhance the gaming experience and provide great exposure for the developer.

We'll also go into more detail about build configuration since we're getting more accustomed to programming. Understanding the importance of configuring your device build is vital for cross-platform development. This is a capability that Corona SDK can handle with ease across iOS and Android devices.

In this chapter, we will learn the following topics:

  • Revisiting configuration settings

  • Posting messages to Twitter

  • Posting messages to Facebook

Let's add in these finishing touches!

Return to configuration


Build settings and runtime configuration were briefly discussed in Chapter 2, Lua Crash Course and the Corona Framework. Let's get into more specific details on how to handle a variety of devices that work on the iOS and Android platforms.

Build configuration

There are a variety of ways to handle device orientation to match the settings your game design requires.

Orientation support (iOS)

There are scenarios in which you want the native user interface (UI) elements to autorotate or to be oriented in a certain way, but you also need to maintain a fixed coordinate system within Corona.

To lock Corona's orientation while allowing the native iPhone UI elements to rotate, add a content parameter in build.settings as follows:

settings =
{
  orientation =
  {
    default = "portrait",
    content = "portrait",
    supported =
    {
      "landscapeLeft", "landscapeRight", "portrait", "portraitUpsideDown",
    },
  },
}

To lock Corona's internal coordinate system to portrait orientation...

Networking your apps


When you have completed developing your main game framework, it's good to think about how to network it if you decide to do this.

At some point in our lives, all of us have used some kind of networking tool, such as Twitter or Facebook. You probably use these applications currently, but the point is that you read updates from other users about a new game that was launched, or someone is spreading the word to download a game and compete with them. You can be that developer and develop the game they're talking about!

Incorporating networking mechanisms in your game does not have to be a hassle. It only takes several lines of code to get it working.

Posting to Twitter

Tweet, tweet, tweet… Twitter is a networking tool that connects you to the latest information that appeals to your interests. It is also a great tool to share information with others about your business and, of course, your game. Reach out to the game development audience by promoting your application.

The user...

Time for action – adding Twitter to your apps


We're going to implement Twitter in our apps by accessing a web service through UI buttons.

  1. In the Chapter 9 folder, copy the Twitter Web Pop-Up project folder to your desktop. All the configuration, libraries, and assets needed are already included. You can download the project files that accompany this book from the Packt Publishing website.

  2. Create a new main.lua file and save it to the project folder.

  3. Set the following variables at the beginning of the code:

    display.setStatusBar( display.HiddenStatusBar )
    
    local ui = require("ui")
    
    local openBtn
    local closeBtn
    local score = 100
  4. Create a local function called onOpenTouch() with an event parameter. Add an if statement so that the event receives a "release" action:

    local onOpenTouch = function( event )
      if event.phase == "release" then
  5. Using the local variable called message, add in the following string statement and concatenate score:

    local message = "Posting to Twitter from Corona SDK and got a final...

Time for action – adding Facebook to your apps


Similar to our Twitter example, we'll be incorporating Facebook posts with a web popup as well:

  1. In the Chapter 9 folder, copy the Facebook Web Pop-Up project folder to your desktop. All the configuration, libraries, and assets needed are already included. You can download the project files that accompany this book from the Packt Publishing website.

  2. Create a new main.lua file and save it to the project folder.

  3. Set the following variables at the beginning of the code:

    display.setStatusBar( display.HiddenStatusBar )
    
    local ui = require("ui")
    
    local openBtn
    local closeBtn
    local score = 100
  4. Create a local function called onOpenTouch() with an event parameter. Add an if statement when the event receives a "release" action:

    local onOpenTouch = function( event )
      if event.phase == "release" then
  5. Add the following local variables that include the strings that we'll be implementing in the Facebook post:

        local appId = "0123456789" -- Your personal FB App...

Facebook Connect


This library supplies a number of functions that provide access to http://www.facebook.com through the official Facebook Connect interface.

Time for action – posting scores using Facebook Connect


Facebook Connect is another way to post on the wall feed by using the native Facebook UI features. We'll be creating a different way to post messages and scores to the newsfeed. In order to see how Facebook Connect operates, you need to load the build to a device to view the results. It will not run in the simulator.

  1. In the Chapter 9 folder, copy the Facebook Connect project folder to your desktop. All the configuration, libraries, and assets needed are already included. You can download the project files that accompany this book from the Packt Publishing website.

  2. Create a new main.lua file and save it to the project folder.

  3. Set up the following variables at the beginning of the code:

    display.setStatusBar( display.HiddenStatusBar )
    
    local ui = require("ui")
    local facebook = require "facebook"
    
    local fbBtn
    local score = 100
  4. Create a local function called onFBTouch() with an event parameter. Add an if statement that contains event.phase =...

Summary


We have covered several more areas on enhancing configuration settings and integrating three of the most popular social networks in today's media in our apps.

We also took an in-depth look into the following:

  • Build settings

  • Dynamic content scaling and dynamic image resolution

  • High-resolution sprite sheets

  • Posting message feeds to Twitter and Facebook

In the next chapter, we will go over the process on how to submit our games to the App Store and Google Play Store. You don't want to miss this for the world!

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Corona SDK Mobile Game Development: Beginner's Guide
Published in: Mar 2015Publisher: ISBN-13: 9781783559343
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)