20,39 €
Physics games are getting more and more popular, and Box2D is the best choice if you are looking for a free, stable and robust library to handle physics. With Box2D you can create every kind of 2D physics game, only coding is not the fun part, but the game itself.
"Box2D for Flash Games" will guide you through the process of making a Flash physics game starting from the bare bones and taking you by hand through complex features such as forces, joints and motors. As you are learning, your game will have more and more features, like the physics games you are used to playing.
The book analyzes two of the most played physics games, and breaks them down to allow readers to build them from scratch in a step-by-step approach.
By the end of the book, you will learn how to create basic primitive bodies as well as complex, compound bodies. Motors will give life to cars, catapults and siege machines firing bullets, while a complete collision management will make your game look even more realistic.
If you want to make full Flash games with physics, then Box2D for Flash Games will guide you through the entire process of making a Flash physics game.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 139
Veröffentlichungsjahr: 2012
Copyright © 2012 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: November 2012
Production Reference: 1161112
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-84951-962-5
www.packtpub.com
Cover Image by Artie Ng (<[email protected]>)
Author
Emanuele Feronato
Reviewers
Joseph Hocking
Ali Raza
Acquisition Editor
Mary Jasmine Nadar
Commissioning Editors
Priyanka Shah
Shreerang Deshpande
Technical Editor
Manmeet Singh Vasir
Copy Editor
Laxmi Subramanian
Project Coordinator
Shraddha Bagadia
Proofreaders
Maria Gould
Cecere Mario
Indexer
Hemangini Bari
Graphics
Aditi Gajjar
Production Coordinator
Prachali Bhiwandkar
Cover Work
Prachali Bhiwandkar
Emanuele Feronato has been studying programming languages since the early 1980s, with a particular interest in game development. He taught online programming for the European Social Fund (ESF) and founded a web development company in Italy.
As a Game Developer, he has developed Flash games sponsored by the biggest game portals and his games have been played more than 70 million times, and he is now porting most of them on mobile platforms.
As a writer, he has worked as a Technical Reviewer for Packt Publishing and published the book Flash Game Development by Example, Packt Publishing.
His blog, www.emanueleferonato.com, is one of the most visited blogs about indie programming.
First of all I would like to give a big thank you to Erin Catto, the guy who developed Box2D, and to Boris the Brave for porting it to AS3.
A thank you also goes to Shraddha Bagadia and the entire Packt Publishing team for believing in this project, as well as to the reviewers for dealing with my drafts and improving the book.
The biggest thank you obviously goes to my blog readers and to my Facebook fans for appreciating my work, giving me the will to write more and more.
I also want to thank my wife Kirenia for being patient while I was writing rather than helping her to paint the house. Awesome job Kirenia!
Joseph Hocking is an interactive media developer living in Chicago. He has spent many years developing Flash games for various companies and freelance clients, and currently works for Synapse Games developing games such as Tyrant and Skyshard Heroes. His development skills include programming web-based games in AS3/Flash, using JavaScript in web pages, writing Python for both client and server applications, and building iPhone games using Lua/Corona SDK.
In addition, Joe also teaches at schools such as the Game Development program at Columbia College. Besides graphics programming, he has a great deal of training and experience in digital arts, including 3D animation. A portfolio of his work can be viewed at www.newarteest.com.
Ali Raza has a master's degree in Computer Science, and more than 8 years of experience as a Designer and Developer. He is also an Adobe Certified Instructor (ACI) and a Microsoft Certified Trainer (MCT).
He is currently working with a UK-based social networking startup as a Senior Developer (Flash Platform), and as a Consultant with a US-based firm ProContent, LLC (team behind Advanced Flash Components). In the past, he has worked with different national and international advertising, telecommunication, and IT firms.
In his free time, Ali enjoys designing and developing cross-platform desktop and mobile applications using Adobe technologies.
Ali has technically reviewed books on Adobe Flash, gaming, and HTML5. He has also published exam aids on Adobe Flex 3 and 4. He was also appointed as a Contributing Editor for Flash & Flex Developer's Magazine in 2011. He can be reached at <[email protected]>.
I would like to express my gratitude to Packt Publishing and the author for bringing about such a wonderful title.
I would also like to thank Priyanka Shah and Shraddha Bagadia for giving me the opportunity to review this amazing book on Box2D.
You might want to visit www.PacktPub.com for support files and downloads related to your book.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
http://PacktLib.PacktPub.com
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read and search across Packt's entire library of books.
If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access.
I want to dedicate this book to my little daughter Kimora. I am sure she will love to read this book although at the moment she prefers Disney's picture books.
I love you "atuncita".
If you look at the most successful Flash games, most of them use physics to add realism and features, which would not have been possible otherwise. This book will guide you through the creation of physics games using Box2D, a free open source physics engine, which is the most used one among game developers. Throughout the book, you will learn how to use Box2D while you create real games.
Chapter 1, Hello Box2D World, introduces what is Box2D, what you can do with it, how to include it in your Flash projects, and your first Box2D world.
Chapter 2, Adding Bodies to the World, explains how to add primitive and complex bodies to the world, and see them displayed on the stage. It also introduces units of measurement.
Chapter 3, Interacting with Bodies, looks at showing how to interact with bodies, selecting them with the mouse, and knowing their position in the world.
Chapter 4, Applying Forces to Bodies, explains how forces and impulses make bodies move in the Box2D world, and how to apply them to animate the world.
Chapter 5, Handling Collisions, answers questions such as: did two bodies collide, was it a hard collision, and where did they collide. We will also discover how to handle collisions among bodies.
Chapter 6, Joints and Motors, explains how to create complex structures using joints, and give them a life applying motors.
Chapter 7, Skinning the Game, explains how to render Box2D world using your own graphic assets.
Chapter 8, Bullets and Sensors, discusses the need for bodies with special attributes. It also explains how to use bullets and sensors for a more accurate simulation and for silent collisions.
Flash CS5 or above is needed. You can download a fully functional free trial of Adobe Flash Professional CS6 from www.adobe.com/go/tryflash/.
Do you already know AS3 basics and want to add to your games a great twist, thanks to physics? Then this book is for you, even if you don't know physics.
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.
To send us general feedback, simply send an e-mail to <[email protected]>, and mention the book title through the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website, or added to any list of existing errata, under the Errata section of that title.
Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <[email protected]> with a link to the suspected pirated material.
We appreciate your help in protecting our authors, and our ability to bring you valuable content.
You can contact us at <[email protected]> if you are having a problem with any aspect of the book, and we will do our best to address it.
If you want to create 2D physics-driven games and applications, Box2D is the best choice available. Box2D is a 2D rigid body simulation library used in some of the most successful games, such as Angry Birds and Tiny Wings on iPhone or Totem Destroyer and Red Remover on Flash. Google them, and you'll see a lot of enthusiastic reviews.
Before we dive into the Box2D World, let me explain what is a rigid body. It's a piece of matter that is so strong that it can't be bent in any way. There is no way to modify its shape, no matter how hard you hit it or throw it. In the real world, you can think about something as hard as a diamond, or even more. Matter coming from outer space that can't be deformed.
Box2D only manages rigid bodies, which will be called just "bodies" from now on, but don't worry, you will also be able to simulate stuff which normally is not rigid, such as bouncing balls.
Let's see what you are about to learn in this chapter:
By the end of the chapter, you will be able to create an empty, yet running world where you can build your awesome physics games.
You can download the latest version of Box2D for Flash either from the official site (http://www.box2dflash.org/download) or from the SourceForge project page (http://sourceforge.net/projects/box2dflash/).
Once you have downloaded the zipped package, extract the Box2D folder (you can find it inside the Source folder) into the same folder you are using for your project. The following is how your awesome game folder should look before you start coding:
You can see the Box2D folder, the FLA file that I am assuming has a document class called Main and therefore Main.as, which is the class we will work on.
I would suggest you work on a 640 x 480 Flash movie at 30 frames per second (fps). The document class should be called Main
