Tải bản đầy đủ (.pdf) (351 trang)

1555 beginning iOS 6 games development

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (13.97 MB, 351 trang )

Learn iPhone and iPad game apps
development using iOS 6 SDK

Beginning

iOS 6 Games
Development
Lucas Jordan
ClayWare
Games

www.it-ebooks.info

tm


For your convenience Apress has placed some of the front
matter material after the index. Please use the Bookmarks
and Contents at a Glance links to access them.

www.it-ebooks.info


Contents at a Glance
About the Author���������������������������������������������������������������������������������������������������������������� xv
About the Technical Reviewer������������������������������������������������������������������������������������������ xvii
Acknowledgments������������������������������������������������������������������������������������������������������������� xix
■■Chapter 1: A Simple First Game�����������������������������������������������������������������������������������������1
■■Chapter 2: Setting up Your Game Project������������������������������������������������������������������������11
■■Chapter 3: Explore the Game Application Life Cycle��������������������������������������������������������37
■■Chapter 4: Quickly Build an Input-Driven Game��������������������������������������������������������������67


■■Chapter 5: Quickly Build a Frame-by-Frame Game���������������������������������������������������������97
■■Chapter 6: Create Your Characters: Game Engine, Image Actors, and Behaviors����������� 131
■■Chapter 7: Build Your Game: Vector Actors and Particles���������������������������������������������159
■■Chapter 8: Building Your Game: Understanding Gestures and Movements�������������������185
■■Chapter 9: Game Center and Social Media��������������������������������������������������������������������221
■■Chapter 10: Monetizing via the Apple App Store�����������������������������������������������������������243
■■Chapter 11: Add Sound to Your Game����������������������������������������������������������������������������259

v

www.it-ebooks.info


vi

Contents at a Glance

■■Chapter 12: A Completed Game: Belt Commander��������������������������������������������������������273
■■Chapter 13: Physics!�����������������������������������������������������������������������������������������������������305
■■Appendix A: Designing and Creating Graphics��������������������������������������������������������������321
Index���������������������������������������������������������������������������������������������������������������������������������341

www.it-ebooks.info


Chapter

1

A Simple First Game

In this book you are going to learn a lot about working with iOS. The goal, of course, is to be able to
build a game that runs on iOS. To do that, you must learn about a lot of different elements that a full
game will incorporate, such as basic UI widgets, audio, complex touch input, Game Center, in-app
purchases, and of course graphics. This book will explore these concepts and many others. Think
of it as a guide to the building blocks that you will need to make a compelling game that is specific
to iOS and Apple’s mobile devices. All iOS applications have one thing in common—the application
Xcode—so it makes sense to start with that.
In this first chapter, we are going to build a very simple game of Rock, Paper, Scissors. We will
use the Storyboard feature of Xcode to create an application with two views and the navigation
between them.
Included with this book are sample Xcode projects; all of the code examples are taken directly from
these projects. In this way, you can follow along with each one in Xcode. I used version 4.5 of Xcode
when creating the projects for this book. The project that accompanies this chapter is called Sample 1;
you can easily build it for yourself by following the steps outlined in this chapter.
The project is a very simple game in which we use Storyboard to create two scenes. The first
scene is the starting view, and the second scene is where the user can play the Rock, Paper,
Scissors game. The second scene is where you will add a UIView and specify the class as
RockPaperScissorView. The source code for the class RockPaperScissorView can be found in the
project Sample 1.
We will walk through each of these steps, but first let’s take a quick look at our game, shown in
Figure 1-1.

1

www.it-ebooks.info


2

CHAPTER 1: A Simple First Game


Figure 1-1.  The two views of our first game: Sample 1

On the left of Figure 1-1 we see the starting view. It just has a simple title and a Play button. When
the user clicks the Play button, he is transitioned to the second view, shown on the right of the
figure. In this view, the user can play Rock, Paper, Scissors. If the user wishes to return to the
starting view, or home screen, he can press the Back button. This simple game is composed of a
Storyboard layout in Xcode and a custom class that implements the game.
Let’s take a look at how I created this game and at some ways you can customize a project.

Creating a Project in Xcode: Sample 1
Creating this game involves only a few steps, which we’ll walk through as an introduction to Xcode.
Start by launching Xcode. From the File menu, select New Project. You will see a screen showing the
types of projects you can create with Xcode (See Figure 1-2).

www.it-ebooks.info


CHAPTER 1: A Simple First Game

3

Figure 1-2.  Project templates in Xcode

For this project, select the template Single View Application. Click Next, and you will be prompted to
name the project, as shown in Figure 1-3.

Figure 1-3.  Naming an Xcode project

www.it-ebooks.info



4

CHAPTER 1: A Simple First Game

Name your project whatever you want. The name you give your project will be the name of the root
folder that contains it. You also want make sure Use Storyboard and Use Automatic Reference
Counting are selected.
This time we will be making an application just for the iPhone, but from the Device Family pull-down
menu you could also select iPad or Universal. After you click Next, you will be prompted to pick a
place to save your project. The project can be saved anywhere on your computer.
Before moving on, let’s take a moment to understand a little about how an Xcode project is
organized.

A Project’s File Structure
 1-4 shows the files created by Xcode.

Figure 1-4.  Files created by Xcode

In Figure 1-4, we see a Finder window showing the file structure created. I selected that I wanted
the project saved on my desktop, so Xcode created a root folder name Sample 1 that contains the
Sample 1.xcodeproj file. The xcodeproj file is the file that describes the project to Xcode, and all
resources are by default relative to that file. Once you have saved your project, Xcode will open your
new project automatically. Then you can start customizing it as you like.

www.it-ebooks.info


CHAPTER 1: A Simple First Game


5

Customizing Your Project
We have looked at how to create a project. Now you are going to learn a little about working
with Xcode to customize your project before moving on to adding a new UIView that implements
the game.

Arranging Xcode Views to Make Life Easier
Once you have a new project created, you can start customizing it. You should have Xcode open
with your new project at this point. Go ahead and click the MainStoryboard.storyboard file found on
the left so your project looks like Figure 1-5.

Figure 1-5.  MainStoryboard.storyboard before customization

In Figure 1-5, we see the file MainStoryboard.storyboard selected (item A). This file is used to
describe multiple views and the navigation relationships between them. It shows the selected
storyboard file and describes the content of the right side of the screen. In item B, we see an item
called View Controller. This is the controller for the view described in item C. The items at D are used
to zoom in and out of a storyboard view, and are critical to successfully navigating your way around.
Additionally, the buttons in item E are used to control which of the main panels are visible in Xcode.
Go ahead and play around with those buttons.
Next, let’s look at how to add a new view.
www.it-ebooks.info


6

CHAPTER 1: A Simple First Game


Adding a New View
Once you have had a chance to play a little with the different view setups available in Xcode, you
can move on and add a new view to your project. Arrange Xcode so the right-most panel is visible,
and hide the left-most panel if you want. Xcode should look something like Figure 1-6.

Figure 1-6.  Storyboard with second view

In Figure 1-6, we see that we have added a second view to the storyboard. Like any good Apple
desktop application, most of the work is done by dragging and dropping. To add the second view,
we enter the word “UIView” into the bottom-right text field, at item A. This filters the list so we can
drag the icon labeled item B on the work area in the center. Click on the new view so it is selected
(see item C), which we can see correlates to the selected icon in item D. Item E shows the properties
for the selected item.
Now that we have a new view in the project, we want to set up a way to navigate between our views.

www.it-ebooks.info


CHAPTER 1: A Simple First Game

7

Simple Navigation
We now want to create some buttons that enable us to navigate from one view to the other. The first
step is to add the buttons, and the second is to configure the navigation. Figure 1-7 shows these
views being wired up for navigation.

Figure 1-7.  Storyboard with navigation

In Figure 1-7, we see that we have dragged a UIButton from the library item A onto each of the

views. We gave the UIButton on the left the label Play, and the UIButton on the right the label Back.
To make the Play button navigate to the view on the right, we right-drag from the Play button (item B)
to the view on the right and release at item C. When we do this, a context dialog pops up, allowing
us to select which type of transition we want. I selected Model. We can repeat the process for the
Back button: right-drag it to the view on the left and select the transition you want for the return trip.
You can run the application at this point and navigate between these two views. In order to make it a
game, though, we need to include the Rock, Paper, Scissors view and buttons.

Adding the Rock, Paper, Scissors View
To add the Rock, Paper, Scissors view, we need to include a class from the sample code in the
project you are building. The easiest way to do this is to open the sample project and drag the

www.it-ebooks.info


8

CHAPTER 1: A Simple First Game

files RockPaperScissorsView.h and RockPaperScissorsView.m from the sample project to your new
project. Figure 1-8 shows the dialog that pops up when you drag files into an Xcode project.

Figure 1-8. Dragging files into an Xcode project

In Figure 1-8, we see the dialog confirming that we want to drag new files into an Xcode project. Be
sure the Destination box is checked. Otherwise, Xcode will not copy the files to the location of the
target project. It is good practice to keep all project resources in the root folder of a project. Xcode
is flexible enough to not require that you do this, but I have been burned too many times by this
flexibility. Anyway, now that we have the required class in our project, let’s wire up our interface to
include it.


Customizing a UIView
The last step in preparing a simple application is to create a new UIView in our interface that is of the
class RockPaperScissorsView. Figure 1-9 shows how this is done.

www.it-ebooks.info


CHAPTER 1: A Simple First Game

Figure 1-9.  A customized UIView

In Figure 1-9, we see a UIView added to the view on the right. We did this by dragging the icon
from item A onto the storyboard in item B. After adjusting the size of the new UIView, we set
its class to be RockPaperScissorsView, as shown in item C. At this point, we are technically
done. We have created our first game! Obviously, we have not looked at the implementation of
RockPaperScissorsView, which is discussed on the next chapter.
The rest of this book will use Sample 1 as a starting place. You will learn many new techniques for
customizing a simple app to make a truly complete game.

Summary
In this chapter, we have taken a quick tour through Xcode, learning how to create a project with
it and build a simple navigation using Storyboard. The chapters that follow will add to the basic
lessons given here to show you how to build a complete game.

www.it-ebooks.info

9



Chapter

2

Setting up Your Game Project
Like all software projects, iOS game development benefits from starting on good footing. In this
chapter, we will discuss setting up a new Xcode project that is a suitable starting point for many
games. This will include creating a project that can be used for the deployment on the iPhone and
the iPad, handling both landscape and portrait orientations.
We look at how an iOS application is initialized and where we can start customizing behavior to
match our expectations of how the application should perform. We will also explore how user
interface (UI) elements are created and modified in an iOS application, paying special attention to
managing different devices and orientations.
The game we create in this chapter will be very much like the simple example from Chapter 1—in
fact, it will play exactly the same. But we will be building a foundation for future chapters while
practicing some key techniques, such as working with UIViewControllers and Interface Builder.
We will explore how an iOS application is put together, and explain the key classes. We’ll also create
new UI elements and learn how to customize them with Interface Builder, and we will explore using
the MVC pattern to create flexible, reusable code elements. At the end of this chapter, we will have
created the Rock, Paper, Scissors application shown in Figure 2-1.

11

www.it-ebooks.info


12

CHAPTER 2: Setting up Your Game Project


Figure 2-1.  An application design to work on the iPhone and iPad in all orientations

Figure 2-1 shows the application running on an iPhone and iPad simulator. This is a so-called
universal application: it can run on both devices and would be presented in the App Store as such.
Unless there are specific business reasons for writing an app that only works on the iPhone or the
iPad, it makes a lot of sense to make your app universal. It will save you time down the road, even if
you only intend to release your app on one of the devices to start.
Our sample application is so simple that it may be difficult to see the differences between the four
states presented in Figure 2-1. On the upper left, where the iPhone is in portrait orientation, the
position of the gray area is laid out differently from the iPhone in landscape at the bottom left. The
layout of the text is also different. The same goes for the application when it is running on the iPad in
landscape vs. portrait. Let’s get going and understand how we can set up a project to accommodate
these different devices and orientations.

www.it-ebooks.info


CHAPTER 2: Setting up Your Game Project

13

Creating Your Game Project
To get things started with our sample game, we first have to create a new project in Xcode.
Create a new project by selecting File ➤ New ➤ New Project . . . . This will open a wizard that allows
you to select which type of project you want, as shown in Figure 2-2.

Figure 2-2.  Creating a new Single View Application

On the left side of Figure 2-2, we have selected Application from the iOS section. On the right
are the available project types for creating iOS applications. The choices presented here help

developers by giving them a reasonable starting place for their applications. This is particularly
helpful for developers new to iOS, because these templates get you started for a number of
common application navigation styles. We are going to pick a Single View Application, because we
require only a very minimal starting point, and the Single View Application provides good support for
universal applications. After clicking Next, we see the options shown in Figure 2-3.

www.it-ebooks.info


14

CHAPTER 2: Setting up Your Game Project

  Details for the new project

The first thing we will do is name our product. You can pick anything you want. The company
identifier will be used during the app submission process to identify it. You can put any value you
want as the company identifier, but it is common practice to use a reverse domain name. As can
be seen in Figure 2-3, the bundle identifier is a composite of the product name and the company
identifier. The bundle identifier can be changed later—the wizard is simply showing what the default
will be. When you submit your game to the App Store, the bundle identifier is used to indicate which
application you are uploading.s
By selecting Universal from the Device list, you are telling Xcode to create a project that is ready to
run on both the iPhone and the iPad. For this example, we will not be using Storyboard or Automatic
Reference Counting. Similarly, we won’t be creating any unit test, so the Include Unit Tests option
should be unchecked as well. Clicking Next prompts you to save the project. Xcode will create a
new folder in the selected directory, so you don’t have to manually create a folder if you don’t want
to. When the new project is saved, you will see something similar to Figure 2-4.

www.it-ebooks.info



CHAPTER 2: Setting up Your Game Project

15

Figure 2-4.  A newly created project

On the left side of Figure 2-4, there is a tree containing the elements of the project with the root-most
element selected (A). On the right, the Summary tab is selected (B). From the Summary tab, we want
to select the supported device orientations (C). To support both orientations on each device, click the
Upside Down button. Scroll down and make sure that all of the orientations for the iPad are depressed
as well. Figure 2-5 shows the correct settings. Now that the project is created, it is time to start
customizing it to fit our needs.

Figure 2-5.  Supporting all device orientations

www.it-ebooks.info


16

CHAPTER 2: Setting up Your Game Project

Customizing a Universal Application
In order to understand the customizations we will make to this project, it is good to know where
we start. The empty project is runnable as is, although it is obviously not very interesting. Take a
moment and run the application. It will look something like the app running in Figure 2-6. Next,
we will be removing the status bar and exploring the best place to start adding custom code to
our project.


Figure 2-6.  A fresh universal iOS application

In Figure 2-6, we see a new universal app running on the iPhone simulator. To run the application on
the iPad simulator, select iPad Simulator from the Scheme pull-down menu to the right of the Stop
button in Xcode. As we can see, the app is empty; there is only a gray background. Another thing
to note is that the status bar at the top of the application is displayed. Although there are plenty
of good reasons to include the status bar in an application, many game developers may wish to
remove the status bar in order to create a more immersive experience. To remove the status bar,
click on the root element in the Project Navigator (the tree on the left in Xcode). Select the target and
then click the Info tab on the right. Figure 2-7 shows the correct view.

www.it-ebooks.info


CHAPTER 2: Setting up Your Game Project

Figure 2-7.  Configuring the status bar

Once you see the view shown in Figure 2-7, right-click on the top-most element (A) and select Add
Row. This will add a new element to the list of items. You will want to set the key value to "Status
bar is initially hidden" and the value to "Yes." What you are doing here is editing the plist
file found under the group Supporting Files. Xcode is simply providing you with a nice interface for
editing this configuration file.

Tip  Navigate to the file ending with info.plist under the group Supporting Files. Right-click
on it and select Open As ➤ Source Code. This will show you the contents of the plist file source.
Note that the key values are actually stored as constants and not as the human readable text used in
the Info editor.


When we run the application again, the status bar is removed, as shown in Figure 2-8.

www.it-ebooks.info

17


18

CHAPTER 2: Setting up Your Game Project

Figure 2-8.  The default application without the status bar

Now that we have explored a simple way to start customizing our application, it is time to investigate
just how an iOS application is put together, so we can make smart decisions about adding our own
functionality.

How an iOS Application Initializes
As we know, iOS applications are written largely in Objective C, which is a superset of C. Xcode
does a good job of hiding the details of how an application is built, but under the covers, we know it
is using LLVM and other common Unix tools to do the real work. Because we know that our project
is ultimately a C application, we would expect the starting point for our application to be a C main
function. In fact, if you look under the Supporting Files group, you will find the main.m, as shown
in Listing 2-1.

www.it-ebooks.info


CHAPTER 2: Setting up Your Game Project


19

Listing 2-1. main.m
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}

The main function in Listing 2-1 is a C function, but you will notice that the body of the function
is clearly Objective C syntax. An @autoreleasepool wraps a call to UIApplicationMain. The
@autoreleasepool sets up the memory management context for this application; we don’t really need
to worry about that. The function UIApplicationMain does a lot of handy stuff for you: it initializes
your application by looking at your info.plist file, sets up an event loop, and generally gets things
going in the right way. In fact, I have never had any reason to modify this function because iOS
provides a concise place to start adding your startup code. The best place to start adding initialization
code is the task application:didFinishLaunchingWithOptions: found in the implementation file of
your app delegate class. In this example, the app delegate class is called AppDelegate. Listing 2-2
shows the implementation of the application:didFinishLaunchingWithOptions: task from
AppDelegate.m.
Listing 2-2. application:didFinishLaunchingWithOptions:
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {

self.viewController = [[[ViewController_iPhone alloc]
initWithNibName:@"ViewController_iPhone" bundle:nil] autorelease];
} else {
self.viewController = [[[ViewController_iPad alloc]
initWithNibName:@"ViewController_iPad" bundle:nil] autorelease];
}
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}

When an application is fully initialized and ready to start running the code that comprises it, the task
application:didFinishLaunchingWithOptions: is called, as seen in Listing 2-2. This task, besides
having an incredibly long name, takes an instance of UIApplication and NSDictionary as arguments.
The UIApplication is an object that represents the state of the running application. The instance of
AppDelegate that receives this message is the delegate to the UIApplication object. This means
that we modify the application’s behavior by implementing tasks in AppDelegate. The protocol

www.it-ebooks.info


20

CHAPTER 2: Setting up Your Game Project

UIApplicationDelegate, which AppDelegate implements, defines the tasks that will be called on the
application’s behalf.
If we take a look at the implementation of application:didFinishLaunchingWithOptions:, we
start by creating a new UIWindow with a size equal to the size of the screen. Once the UIWindow is
instantiated, we need to create a UIViewController that will manage the UI of our application. A

new Xcode project, like the one we created, starts out with a single ViewController class to manage
our UI. We are going to create device-specific subclasses of our ViewController, so that we have a
place to put device-specific code. We will look at the process of creating these subclasses shortly.
To make sure that we instantiate the correct ViewController subclass, we need to add the bold code
in Listing 2-2.
Once our ViewController is created, we set it as the rootViewController of window and call
. The window object is an instance of UIWindow and is the root graphical
makeKeyAndVisible essentially displays the window. Any
window object.
makeKeyAndVisible. This might include reading an app-specific

iOS development and the associated libraries make heavy use of the Model View Controller (MVC)
pattern. In general, MVC is a strategy for separating the presentation (View), data (Model), and
business logic (Controller). In specific terms, the model is simply data, like a Person class or an
Address. The view is responsible for rendering the data to the screen. In iOS development, that
means a subclass of UIView. iOS provides a special class to act as the controller for a UIView, which
is aptly named UIViewController.
UIViewController has two key characteristics: it is often associated with an XIB file, and it has
a property called “view” that is of type UIView. By creating a subclass of UIViewController, we
can also make an XIB file with the same name as the class. By default, when you instantiate a
UIViewController subclass, it will load a XIB with the same name. The root UIView in the XIB will be
wired up as the view property of UIViewController.
Besides providing a clean separation between the UI layout and the logic that drives it, iOS provides
a number of UIViewController subclasses that expect to work with other UIViewControllers
instead of UIViews. An example of this is the UINavigationController that implements the type of
navigation found in the Settings app. In code, when you want to advance to the next view, you pass
a UIViewController and not a UIView, though it is the view property of the UIViewController that is
displayed on the screen.
Admittedly, for our example application in this chapter, it does not make a lot of difference if we use
a UIViewController. In Chapter 1, we extended UIView when we created the RockPaperScissorsView

class and it worked fine. However, understanding how UIViewControllers and their views work
together will make life easier in Chapter 3, where we explore a game’s application life cycle.
www.it-ebooks.info


CHAPTER 2: Setting up Your Game Project

21

Using the RockPaperScissorsView from Chapter 1, let’s take a look at how this functionality
would appear if it were implemented as a UIViewController. Listing 2-3 shows the file
RockPaperScissorsController.h.
Listing 2-3.  RockPaperScissorsController.h
@interface RockPaperScissorsController : UIViewController {
UIView* buttonView;
UIButton* rockButton;
UIButton* paperButton;
UIButton* scissersButton;

UIView* resultView;
UILabel* resultLabel;
UIButton* continueButton;

BOOL isSetup;
}
-(void)setup:(CGSize)size;
-(void)userSelected:(id)sender;
-(void)continueGame:(id)sender;

-(NSString*)getLostTo:(NSString*)selection;

-(NSString*)getWonTo:(NSString*)selection;
@end

In Listing 2-3, we see the class RockPaperScissorsController extends UIViewController. Among
other things, this means that RockPaperScissorsController has a property called "view" that will be
the root UIView for this controller. Like RockPaperScissorsView, we will have other UIViews that are
subviews of the root view, such as the buttons for selecting your choice. Although these buttons
could conceivably have their own UIViewControllers, there comes a point when it makes sense to
allow a UIViewController to manage all of the UIViews with which it is concerned. There are very
few changes required on the implementation side of things to complete this transition from UIView
to UIViewController. Basically, wherever we used the keyword "self," we simply say self.view
instead. Listing 2-4 shows the required changes.
Listing 2-4.  RockPaperScissorsController.m (Partial)
-(void)setup:(CGSize)size{

if (!isSetup){
isSetup = true;

srand(time(NULL));

buttonView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
[buttonView setBackgroundColor:[UIColor lightGrayColor]];
[self.view addSubview:buttonView];


www.it-ebooks.info


22


CHAPTER 2: Setting up Your Game Project

float sixtyPercent = size.width * .6;
float twentyPercent = size.width * .2;
float twentFivePercent = size.height/4;
float thirtyThreePercent = size.height/3;

rockButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[rockButton setFrame:CGRectMake(twentyPercent, twentFivePercent, sixtyPercent, 40)];
[rockButton setTitle:@"Rock" forState:UIControlStateNormal];
[rockButton addTarget:self action:@selector(userSelected:)
forControlEvents:UIControlEventTouchUpInside];

paperButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[paperButton setFrame:CGRectMake(twentyPercent, twentFivePercent*2, sixtyPercent, 40)];
[paperButton setTitle:@"Paper" forState:UIControlStateNormal];
[paperButton addTarget:self action:@selector(userSelected:)

scissersButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[scissersButton setFrame:CGRectMake(twentyPercent, twentFivePercent*3, sixtyPercent, 40)];
[scissersButton setTitle:@"Scissers" forState:UIControlStateNormal];
[scissersButton addTarget:self action:@selector(userSelected:)

[buttonView addSubview:rockButton];
[buttonView addSubview:paperButton];
[buttonView addSubview:scissersButton];


resultView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
[resultView setBackgroundColor:[UIColor lightGrayColor]];


resultLabel = [[UILabel new] initWithFrame:CGRectMake(twentyPercent, thirtyThreePercent,
sixtyPercent, 40)];
[resultLabel setAdjustsFontSizeToFitWidth:YES];
[resultView addSubview:resultLabel];

continueButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[continueButton setFrame:CGRectMake(twentyPercent, thirtyThreePercent*2, sixtyPercent, 40)];
[continueButton setTitle:@"Continue" forState:UIControlStateNormal];
[continueButton addTarget:self action:@selector(continueGame:)
forControlEvents:UIControlEventTouchUpInside];
[resultView addSubview:continueButton];

}
}

www.it-ebooks.info


×