www.it-ebooks.info Adobe Flash 11 Stage3D (Molehill) Game Programming Beginner's Guide A step-by-step guide for creang stunning 3D games in Flash 11 Stage3D (Molehill) using AS3 and AGAL Christer Kaila BIRMINGHAM - MUMBAI www.it-ebooks.info Adobe Flash 11 Stage3D (Molehill) Game Programming Beginner's Guide Copyright © 2011 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmied in any form or by any means, without the prior wrien permission of the publisher, except in the case of brief quotaons embedded in crical arcles or reviews. Every eort has been made in the preparaon of this book to ensure the accuracy of the informaon presented. However, the informaon 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 informaon about all of the companies and products menoned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this informaon. First published: November 2011 Producon Reference: 1181111 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-84969-168-0 www.packtpub.com Cover Image by Asher Wishkerman (wishkerman@hotmail.com) www.it-ebooks.info Credits Author Christer Kaila Reviewers Arthy Shane Johnson Acquision Editor Tarun Singh Development Editor Maitreya Bhakal Technical Editor Azharuddin Sheikh Indexer Hemangini Bari Project Coordinators Kushal Bhardwaj Srimoyee Ghoshal Proofreader Kevin McGowan Graphics Valenna D'souza Producon Coordinator Shantanu Zagade Cover Work Shantanu Zagade www.it-ebooks.info About the Author Christer Kaila, B.Sc., is a veteran video game developer with 17 years of professional experience. A hardcore gamer, dad, dungeon master, arst, and musician, he never takes himself too seriously and loves what he does for a living: making games! A child of the arcade scene, he programmed his rst video game in the Eighes, long before the Internet or hard drives existed. The rst programming language he ever learned was 6809 assembly language, followed by BASIC, Turbo Pascal, VB, C++, Lingo, PHP, Javascript, and nally AconScript. He grew up as an elite BBS sysop in the MS-DOS era and was an acve member of the demo scene in his teens. He put himself through university by providing freelance soware programming services for clients. Since then, he has been an acve member of the indie game development community and is known by his fellow indies as Breakdance McFunkypants. Christer frequently joins game jams to keep his skills on the cung edge of technology, is always happy to help people out with their projects by providing enthusiasc encouragement, and plays an acve part helping to nd bugs in Adobe products that have not yet been made public. Over the years, he has programmed puzzle games, mulplayer RPGs, acon tles, shooters, racing games, chat rooms, persistent online worlds, browser games, and many business applicaons for clients ranging from 3D displays for industrial devices to simulaons made for engineers. He is the curator of a popular news website called www.videogamecoder.com which syndicates news from hundreds of other game developer blogs. He would love to hear from you on twier (www.twitter.com/McFunkypants) or Google+ (http://www.mcfunkypants.com/+) and is always happy to connect with his fellow game developers. www.it-ebooks.info His client work porolio is available at www.orangeview.net and his personal game development blog is www.mcfunkypants.com where you can read more about the indie game community and his recent projects. He lives in Victoria, Canada with his beloved wife and the cutest baby son you have ever seen. This book would not have been possible without valuable contribuons of source code, tutorials and blog posts by Thibault Imbert, Ryan Speets, Alejandro Santander, Mikko Haapoja, Evan Miller, Terry Paton, and many other fellow game developers from the ever-supporve Flash community. Thank you for sharing. Your hard work is humbly and respecully appreciated. www.it-ebooks.info About the Reviewers Arthy is a French senior ash developer, as well as a big video gaming fan. With 10 years of experience in Flash development for web agencies, his preference is clearly for video games development. Arthy began his video games experience as a junior producer at Atari (Lyon, FRANCE). Since then he went back behind the keyboard and entered the web Flash-based developments in 2001 for a French web agency, Megalos. Then, to focus on Flash games development, he decided to work on his own as a freelance developer, and so created his company, Le Crabe. Aer two years of freelancing, he created and joined a freelance associaon: L'étrange Fabrique. Recently, he le the freelance world and entered another adventure with a Swiss company: Blue innity. Shane Johnson has been working as a developer for the last four years, both freelance and contractually, creang engaging and creave applicaons for the web, desktop, and also mobile devices with not only Flash, but also any medium that he feels is the right tool to do the job. Primarily an AconScript developer, Shane also enjoys programming with any language, as it is his real drive to create things using maths and any technology that gets him going. Since the launch of the Adobe Molehill Incubator program for Flash Player 11, Shane has been involved in experimenng with the new API, creang many examples with some of the new Molehill frameworks that are emerging. Shane is also an Adobe Cered Expert and maintains a blog at http://blog.ultravisual.co.uk, as well as being a consistent contributor to http://active.tutsplus.com/. www.it-ebooks.info www.PacktPub.com Support les, eBooks, discount offers and more You might want to visit www.PacktPub.com for support les and downloads related to your book. Did you know that Packt oers eBook versions of every book published, with PDF and ePub les available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entled to a discount on the eBook copy. Get in touch with us at service@ packtpub.com for more details. At www.PacktPub.com, you can also read a collecon of free technical arcles, sign up for a range of free newsleers and receive exclusive discounts and oers on Packt books and eBooks. http://PacktLib.PacktPub.com Do you need instant soluons to your IT quesons? PacktLib is Packt’s online digital book library. Here, you can access, read and search across Packt’s enre library of books. Why Subscribe? Fully searchable across every book published by Packt Copy and paste, print and bookmark content On demand and accessible via web browser Free Access for Packt account holders If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine enrely free books. Simply use your login credenals for immediate access. www.it-ebooks.info www.it-ebooks.info This book is dedicated to my loving wife, Kristyn, who recently gave birth to our newborn son, James. Every day I am grateful for the joy you bring to my life. You movate me. Inspire me. Encourage me. Fill me with happiness and pie! I'm the luckiest man in the world. www.it-ebooks.info [...]... this book is for If you ever wanted to make your own 3D game in Flash, then this book is for you This book is a perfect introduction to 3D game programming in Adobe Molehill for complete beginners You do not need to know anything about Stage3D/ Molehill or Flash 11 in order to take advantage of the examples in this book This book assumes that you have programming experience in AS3 (ActionScript 3) Conventions... boring appendix of every Stage3D command listed in order That information can be found using Google Instead, we will start from scratch and gradually explore deeper into the world of 3D Flash games, one skill at a time It will be example-heavy and filled with information that you can use in real-life game development using the Flash 11 Stage3D API www.it-ebooks.info Let’s Make a Game Using Molehill! Your... make your very own 3D games in Flash www.it-ebooks.info Preface What this book covers Chapter 1, Let's Make a Game Using Molehill! In this chapter, we talk about what Stage3D (Molehill) is, what it can do, and the basic terminology you need to know when dealing with 3D games Chapter 2, Blueprint of a Molehill In this chapter, we compare the differences between old-fashioned Flash games and the new way... Making our game more interactive Adding a HUD overlay graphic Time for action – adding a GUI overlay Keeping track of time: a game timer class Time for action – creating the game timer class Time for action – adding the GameTimer class constructor Time for action – implementing the tick function A game input class Time for action – creating the GameInput class Time for action – coding the GameInput... Preface Adobe' s Stage3D (previously codenamed Molehill) is a set of 3D APIs that has brought 3D to the Flash platform Being a completely new technology, there were almost no resources to get you acquainted with this revolutionary platform, until now This book will show you how to make your very own next-gen 3D games in Flash If you have ever dreamed of writing your own console-style 3D game in Flash, ... chapter presents a deeper and more complete video game as an example project From a simple tech demo, your game will grow to become a finished product—your very own playable 3D game filled with animation, special effects, sounds, and tons of action The goal of this book is to teach you how to program a complete game in Stage3D that has a beginning, middle, and game over As you progress further into your... achieved! Summary Level 1 achieved! www.it-ebooks.info 8 8 9 9 10 10 11 11 12 12 13 13 14 15 15 16 17 18 19 22 22 Table of Contents Chapter 2: Blueprint of a Molehill 23 The old fashioned way 23 The Molehill way: Stage3D 24 Using 2D Flash text and sprites 25 Why is Stage3D so fast? 25 The structure of a Molehill application 26 Stage 27 Stage3D 27 Context3D 27 VertexBuffer3D 28 IndexBuffer3D 28 Program3D... will be working with and the structure of a typical Stage3D game Chapter 3, Fire up the Engines In this chapter, we take the first step by setting up our tools and programming the initializations for our game The result is a demo that gets Stage3D to animate a simple 3D mesh Chapter 4, Basic Shaders: I can see Something! In this chapter, we learn about programming shaders using AGAL and adding text to... up the Engines! 33 Step 1: Downloading Flash 11 (Molehill) from Adobe Time for action – getting the plugin Time for action – getting the Flash 11 profile for CS5 Time for action – upgrading Flex Time for action – upgrading the Flex playerglobal.swc Time for action – using SWF Version 13 when compiling in Flex Time for action – updating your template HTML file Stage3D is now set up! Step 2: Start coding... accelerated power of Stage3D This book will lead you step-by-step through the process of programming a 3D game in ActionScript 3 using this exciting new technology Filled with examples, pictures, and source code, this is a practical and fun-to-read guide that will benefit both 3D programming beginners and expert game developers alike Starting with simple tasks such as setting up Flash to render a simple . www.it-ebooks.info Adobe Flash 11 Stage3D (Molehill) Game Programming Beginner's Guide A step-by-step guide for creang stunning 3D games in Flash 11 Stage3D (Molehill) using AS3. AGAL Christer Kaila BIRMINGHAM - MUMBAI www.it-ebooks.info Adobe Flash 11 Stage3D (Molehill) Game Programming Beginner's Guide Copyright © 2 011 Packt Publishing All rights reserved. No part of. Publishing cannot guarantee the accuracy of this informaon. First published: November 2 011 Producon Reference: 118 1111 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham