وبلاگ بلیان

Flash Mobile: Building Games With Flash For The Mobile Market: Building Games With Flash For The Mobile Market

معرفی کتاب «Flash Mobile: Building Games With Flash For The Mobile Market: Building Games With Flash For The Mobile Market» نوشتهٔ Matthew David، منتشرشده توسط نشر Focal Press [Imprint]; Elsevier Science & Technology Books; Elsevier [Distributor] در سال 2010. این کتاب در فرمت pdf، زبان انگلیسی ارائه شده است.

Chapter One BUILDING GAMES WITH FLASH FOR THE MOBILE MARKET Almost a third of all apps developed for the Android and iOS are games. In this section we introduce you to game development on the Android and iOS. Getting Started with Game Development There are more than 50,000 games in the iTunes App Store and 20,000 in the Android Market Place (Figure 5.1). They range from simple word puzzles to complex 3D strategy games. In this section you will learn the basics needed for game development: • Understanding what you want your game to be • Planning, planning, planning • Using Flash to do the heavy work • Developing your game to work on all devices Often the biggest decision you need to make when developing a game is, what do I want the game to do? Think about this long and hard. The reality is that no game is created quickly; you will spend a lot of time on your game and you want to ensure that the game is worth your time. In many ways, Flash is maturing into an ideal platform for game development. Advances in the Flash Player and the work the Flash Team at Adobe have put into AIR allow you to perform almost limitless tasks in Flash. For instance, you can create simple card games, logic games, or even complex multiplayer games. In fact, the most popular game on the planet, FarmVille, is written in Flash. Want to take it up a notch with 3D, no problem. Flash will handle your 3D worlds just fine. When you have decided what type of game you want to develop, the next stage is planning. OK, I know this may not be the most thrilling part of game design, but it is in many ways the most important. You simply don't want to just jump in and begin coding. With the OOP program structure in AS3, you do need to think ahead. With that said, you can break down the structure of your game into the following sections: • For whom is the game intended? • What type of game is it? • What will the screens of the game look like? • What sounds and visuals do you need for the game? • What is the target device for your game? Understanding your audience is a big part of game design. Are you building a game that is for anyone, such as your mother or aunt, or are you targeting a specific group, such as teen boys (yeah, we want lots of blood and violence!). Get it down on paper, in an e-mail, or a tweet, just so you know who you want buying your game. This will keep your focus through the game development life cycle. The following screen shot shows a selection of games available on Apple's iTunes App Store. When you know your intended audience, you next need to know what type of game you want to develop. There are simply loads of game options for Flash, as mentioned earlier. Some common types include parlor games (games that can be played and learned in 30 seconds or less); role-playing games, such as FarmVille, where you can play the game for the rest of your life; and even complex physics games where you are colliding with objects all over the place. The reason why you have so many choices when it comes to game development is simple: ActionScript 3.0 (AS3). The AS3 AVM is simply very powerful and gives you the opportunity to flex your programming muscles. Screen design and development is a lot of fun. You will enjoy this part of your game development. There are lots of ways to develop your screen; the way I like to approach screen design is simply to get a notepad, permanent marker, and an open mind. Draw screens out on the notepad. Scratch out and restart as many times as needed until you have the designs that make you feel most comfortable. The objective is to get ideas down on paper. When you have your ideas on paper you have a choice: either leave them as draft ideas or flesh them out with greater detail. My personal preference is to leave them as rough drawings. Tweaks and modifications can be made later. Games are multisensory. You will want to ensure that you address this by adding audio and visual feedback to your audience as they play your games. It is worth buying some good graphics. Don't use clip artmdash;it always looks like you used clip art and looks shoddy. There are lots of ways of getting sounds. Some of the best resources are buying collections of sounds from the BBC, Sony, or Warner Bros. Each company has sound effect files you can download and use in your project (Figure 5.3). The final choice you need to make is to decide for which device you will design your game. Is this an iPad game, an Android game, or one for the BlackBerry Tablet? Each device is different in shape, the speed of the CPU/GPU, and technology. Flash can handle a lot, but a game for the iPod Touch is going to look different when run on a tablet. After you have gone through this process you are now ready to start developing your game. Making It Easier to Write Code with Libraries Code development is a lot of work. Creating simple scripts takes time. As you can imagine, game development gets even more complicated. To help you get through this problem you will want to leverage code libraries. A library is a collection of AS3 classes that perform specific functions: they may be animation, collision detection, physics, 3D, or more. There are a lot of libraries you can use. Before jumping into specific Game Engine libraries, let's look at some general code libraries that will help you in your game development. There are essentially three groups of libraries you should be concerned about as a game developer: • Utilities • Animation • 3D This game does not contain more specific game engine tools, such as physics engines, but we will get to that soon enough. In many ways, this collection of libraries can be used for any application you develop for your mobile device—they all run on AS3. The news keeps getting better. All of these libraries are free and open source. You can start using them in your projects right now without spending a single penny. Adding a Library to Your Project Libraries can be added quite easily to your project. Generally, you will download a library in a single ZIP file. The file will contain a folder or collection of folders with the code. Find your application folder and include the new library folders in the same directory. The next step is to link to the library from your ActionScript code. The following example demonstrates how you can do this with GreenSock's TweenMax animation library. The first step is to download the AS3 library (Figure 5.4). Depending on which library you use will depend on where you can find it. For TweenMax you can go straight to www.greensock.com and find the link right off the home page. Make sure you select the AS3 version of TweenMax. As with many libraries, TweenMax comes in AS2 and AS3 flavors. As we said earlier in this book, AS2 is not supported in mobile devices. The file you download will be a ZIP folder (Figure 5.5). The folder contains a lot of content, but most of it is documentation and you do not need it in your project. What you do need is the folder called COM. Locate the COM folder and copy it to the same folder as your Flash project. What is inside the COM folder? It is all the classes and goodness that you need for adding dozens of different types of animation to your projects. You do not need to add complexity when you have these classes. For example, the TweenMax class structure manages all the events, getters/setters, animation types (there are a lot), layout, loading, data, motion paths, and much, much more. The following is just one small example of the work GreenSock has done for you. This is the class library that allows you to add Elastic animation type to your project: package com.greensock.easing { public class Elastic { private static const _2PI:Number = Math.PI • 2; public static function easeIn (t:Number, b:Number, c:Number, d:Number, a:Number = 0, p:Number = 0):Number { var s:Number; if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d•.3; if (!a || (c > 0 && a < c) || (c < 0 && a 0 && a < c) || (c < 0 && a 0 && a < c) || (c < 0 && a < -c)) { a=c; s = p/4; } else s = p/_2PI • Math.asin (c/a); if (t < 1) return -.5•(a•Math.pow(2,10•(t-=1)) • Math.sin( (t•d-s)•_2PI/p )) + b; return a•Math.pow(2,-10•(t-=1)) • Math.sin( (t•d-s)•_2PI/p )•.5 + c + b; } } } That is a lot of complex code. And you do not need to write it. To get this type of animation into your project you simply need to reference the library, its exposed classes, and add it to your own project. To do this, you will need to save a Flash Professional file into the same directory as your library, the folder with the COM folder. Open the Actions panel and add the following: import com.greensock.TweenMax; This command will import that TweenMax class. In turn, the TweenMax class will then import all the other Class files and allow you to add them to your project. Now, let's see how easy it is to add the Elastic animation to your project. Create a simple drawing in Flash and convert it into a movie clip instance. Name the instance myAnimation. Place the movie clip in the center of the stage. The objective will be to use the Elastic animation sequence to add animation to move the movie clip named myAnimation into the top left-hand corner. In the Actions panel add the following: TweenMax.to(myAnimation, 1, {x:0, y:0, ease:Elastic. easeIn}); Test your animation. Your animation should now work using just two lines of code. As you can see, libraries can dramatically reduce the amount of work needed to add core functionality. Working with Utility Libraries A utility is a tool that performs a function that is under the hood. This group includes data control, security, and other functions that the user does not see. Using AS3CoreLib The first library you will want to use is AS3CoreLib (Figure 5.6). The library is written by some of the leading Flash Evangelists—Mike Chambers, Christian Cantrell, Figure 5.6 AS3CoreLib contains Tinic Uro, et al.—and covers some very important behind-the-scenes features around security. AS3CoreLib allows you to easily leverage the following in your code: • MD5 hash • SHA1 hash • JSON library (serialization and deserialization) • JPEG and PNG encoding • HTTP Utility and Helper Classes • Array, String, Date, Number, and XML Utility APIs The AS3CoreLib can be downloaded at http://github.com/ mikechambers/as3corelib. Using AS3Crypto As the name suggests, AS3Crypto is a library designed to add ways in which you can encrypt your data coming in and out of Flash (Figure 5.7). This library includes the ability to connect with SSL. The list of supported cryptography is very impressive. You can use the following: • Protocols: TLS 1.0 support (partial) • Certificates: X.509 Certificate parsing and validation, built-in Root CAs • Public key encryption: RSA (encrypt/decrypt, sign/verify) • Secret key encryption: AES, DES, 3DES, BlowFish, XTEA, RC4 • Confidentiality modes: ECB, CBC, CFB, CFB8, OFB, CTR • Hashing algorithms: MD2, MD5, SHA-1, SHA-224, SHA-256 • Paddings available: PKCS#5, PKCS#1 type 1 and 2 • Other useful stuff: HMAC, Random, TLS-PRF, some ASN-1/ DER parsing The library can be downloaded at http://code.google.com/p/ as3crypto/ . One note of caution when building iOS apps with cryptography: You must ensure that you declare what type of cryptography you are using when you submit your app to the App Store. If you do not, Apple will reject your app. Using AS3eBayLib The AS3eBayLib allows you to easily connect to eBay's public XML API files. This allows you to create novel and unique experiences with eBay's massive amount of content and ecommerce. You can download the library (Figure 5.8) at http://code.google .com/p/as3ebaylib/ . Using PureMVC Model View Controller (MVC) is a classic architecture (Figure 5.9) where you separate all elements of your code, UI, and data. Typically, if you are writing Class files and using XML, then you are indirectly doing this in Flash already. But , you can always do better. This set of classes forces a set of best practices when using MVC in your development. You can download the code at http://puremvc.org/. (Continues...) Excerpted from BUILDING GAMES WITH FLASH FOR THE MOBILE MARKET by MATTHEW DAVID Copyright © 2011 by Elsevier Inc. . Excerpted by permission of Focal Press. All rights reserved. No part of this excerpt may be reproduced or reprinted without permission in writing from the publisher. Excerpts are provided by Dial-A-Book Inc. solely for the personal use of visitors to this web site. Building Games with Flash for the Mobile Market......Page 2 Copyright......Page 3 Contents......Page 4 Getting Started with Game Development......Page 5 Making It Easier to Write Code with Libraries......Page 8 Using Game Engines......Page 27 Developing Your Game......Page 43
دانلود کتاب Flash Mobile: Building Games With Flash For The Mobile Market: Building Games With Flash For The Mobile Market