Adobe Flash 11 Stage3D (Molehill) Game Programming Beginner’s Guide


Adobe Flash 11 Stage3D (Molehill) Game Programming Beginner’s Guide
eBook: $29.99
Formats: PDF, PacktLib, ePub and Mobi formats
$21.00
save 30%!
Print + free eBook + free PacktLib access to the book: $79.98    Print cover: $49.99
$70.99
save 11%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Overview
Table of Contents
Author
Support
Sample Chapters
  • The first book on Adobe's Flash 11 Stage3D, previously codenamed Molehill
  • Build hardware-accelerated 3D games with a blazingly fast frame rate.
  • Full of screenshots and ActionScript 3 source code, each chapter builds upon a real-world example game project step-by-step.
  • Light-hearted and informal, this book is your trusty sidekick on an epic quest to create your very own 3D Flash game.
  • This is the game you will create after you are done with the book: PLAY THE DEMO GAME

Book Details

Language : English
Paperback : 412 pages [ 235mm x 191mm ]
Release Date : November 2011
ISBN : 1849691681
ISBN 13 : 9781849691680
Author(s) : Christer Kaitila
Topics and Technologies : All Books, Game Development, Flash, Beginner's Guides, Games, Web Graphics & Video

Table of Contents

Preface
Chapter 1: Let's Make a Game Using Molehill!
Chapter 2: Blueprint of a Molehill
Chapter 3: Fire up the Engines!
Chapter 4: Basic Shaders: I can see Something!
Chapter 5: Building a 3D World
Chapter 6: Textures: Making Things Look Pretty
Chapter 7: Timers, Inputs, and Entities: Gameplay Goodness!
Chapter 8: Eye-Candy Aplenty!
Chapter 9: A World Filled with Action
Chapter 10: 3... 2... 1... ACTION!
Appendix A: AGAL Operand Reference
Appendix B: Pop Quiz Answers
Index
  • Chapter 1: Let's Make a Game Using Molehill!
    • Your epic adventure awaits!
    • What is Molehill?
    • What Molehill is NOT
    • What you need to know already
    • Basic 3D terminology
    • Common 3D content terms
      • Mesh
      • Polygon
      • Vertex
      • Texture
      • Shaders
      • Vertex program
      • Fragment program
      • 3D Content level one achieved!
    • Common 3D coding terms
      • Vectors
      • Normals
      • Matrices
      • 3D Coding level one achieved!
    • Summary
    • Level 1 achieved!
    • Chapter 2: Blueprint of a Molehill
      • The old fashioned way
      • The Molehill way: Stage3D
      • Using 2D Flash text and sprites
      • Why is Stage3D so fast?
      • The structure of a Molehill application
        • Stage
        • Stage3D
        • Context3D
        • VertexBuffer3D
        • IndexBuffer3D
        • Program3D
      • Flowchart of a Molehill program
      • Time for action – things we do once, during the setup
      • Time for action – things we do over and over again
      • Summary
      • Level 2 achieved!
      • Chapter 3: Fire up the Engines!
        • 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
        • Time for action – creating an empty project
        • Time for action – importing Stage3D-specific classes
        • Time for action – initializing Molehill
        • Time for action – defining some variables
        • Time for action – embedding a texture
        • Time for action – defining the geometry of your 3D mesh
        • Time for action – starting your engines
        • Time for action – adding to the onContext3DCreate function
        • Time for action – uploading our data
        • Time for action – setting up the camera
        • Time for action – let's animate
        • Time for action – setting the render state and drawing the mesh
          • Quest complete – time to reap the rewards
          • Congratulations!
        • The entire source code
        • Summary
        • Level 3 achieved!
        • Chapter 4: Basic Shaders: I can see Something!
          • AGAL: Adobe Graphics Assembly Language
            • What does one line of AGAL look like?
            • What is a register?
            • What is a component?
            • Working with four components at the same time
            • Different registers for different jobs
              • Vertex attribute registers: va0..va7
              • Constant registers: vc0..vc127 and fc0..fc27
              • Temporary registers: vt0..vt7 and ft0..ft7
              • Output registers: op and oc
              • Varying registers: v0..v7
              • Texture samplers: fs0..fs7
          • A basic AGAL shader example
            • The vertex program
          • Time for action – writing your first vertex program
            • The fragment program
          • Time for action – writing your first fragment program
          • Compiling the AGAL source code
          • Time for action – compiling AGAL
          • Time to Render!
          • Time for action – rendering
          • Creating a shader demo
          • Adding an FPS counter
          • Time for action – creating the FPS GUI
          • Time for action – adding the GUI to our inits
          • Time for action – adding multiple shaders to the demo
          • Time for action – initializing the shaders
          • Time for action – animating the shaders
          • Time for action – uploading data to Stage3D
            • Quest complete—time to reap the rewards
            • Congratulations!
          • Summary
          • Level 4 achieved!
          • Chapter 5: Building a 3D World
            • Creating vertex buffers
              • Importing 3D models into Flash
            • Time for action – coding the Stage3dObjParser class
            • Time for action – creating the class constructor function
            • Time for action – coding the parsing functions
            • Time for action – processing the data
            • Time for action – coding some handy utility functions
              • Our mesh parsing class is complete!
            • The render loop
            • Time for action – starting the render loop
            • Time for action – adding the score to the GUI
            • Time for action – upgrading your init routines
            • Time for action – parsing our mesh data
            • Time for action – animating the scene
              • Quest complete—time to reap the rewards
            • Folder structure
            • Summary
            • Level 5 achieved!
            • Chapter 6: Textures: Making Things Look Pretty
              • Time for a plan: creating a "real" game
              • Using textures in Stage3D
                • Power-of-two
                • UV coordinates
                • Transparent textures
                • Animating UV coordinates in a shader
              • Time for action – updating UV coordinates each frame
                • Texture atlases
                • Animated textures
                • Manipulating texture data
              • Render states
                • Backface culling
              • Time for action – rendering a mesh's backfaces
                • Depth testing
              • Time for action – making a mesh not affect the zbuffer
                • Blend modes
              • Time for action – rendering an opaque mesh
              • Time for action – rendering a mesh with transparent regions
              • Time for action – rendering a mesh so it lightens the scene
              • Increasing your performance
                • Opaque is faster
                • Avoiding overdraw
                • Avoiding state changes
                • Use simple shaders
                • Draw fewer meshes
              • Adding texture effects to our demo
              • Time for action – embedding the new art
              • Time for action – adding the variables we need
              • Time for action – upgrading the GUI
              • Time for action – listening for key presses
              • Time for action – upgrading our render loop
              • Time for action – upgrading the renderTerrain function
              • Time for action – upgrading our Stage3D inits
              • Time for action – simplifying the initShaders function
              • Time for action – parsing the new meshes
              • Time for action – rendering different meshes as appropriate
              • Time for action – switching textures
              • Time for action – switching blend modes
              • Your demo has been upgraded!
              • Summary
              • Level 6 achieved!
              • Chapter 7: Timers, Inputs, and Entities: Gameplay Goodness!
                • Our current quest
                  • Keeping it simple
                  • Making it reusable
                • 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 class constructor
                • Time for action – detecting mouse movement
                • Time for action – detecting the keyboard input
                • Time for action – detecting key release events
                • Time for action – detecting the input focus
                  • An abstract entity class
                • Time for action – creating the Stage3dEntity class
                • Time for action – creating the Stage3dEntity class constructor
                • Hiding complex code by using get and set functions
                • Time for action – getting and setting the transform
                • Time for action – getting and setting the entity position
                • Time for action – getting and setting the entity rotation
                • Time for action – getting and setting the entity's scale
                • Time for action – updating the transform or values on demand
                • Time for action – creating the movement utility functions
                • Time for action – implementing vector utility functions
                • Time for action – adding some handy entity utility functions
                • Time for action – cloning an entity
                • Time for action – rendering an entity
                • Design art for our new improved game world
                • Upgrading our game
                • Time for action – importing our new classes
                • Time for action – adding new variables to our game
                • Time for action – embedding the new art
                • Time for action – upgrading the game inits
                • Time for action – upgrading the GUI
                • Time for action – simplifying the shaders
                • Time for action – using the new textures
                • Time for action – spawning some game entities
                • Time for action – upgrading the render function
                • Time for action – creating a simulation step function
                • Time for action – creating a heartbeat function
                • Time for action – upgrading the enterFrame function
                • Let's see all this in action!
                • Summary
                • Level 7 achieved!
                • Chapter 8: Eye-Candy Aplenty!
                  • Our current quest
                    • Designing for performance
                    • Designing for reusability
                    • Animating using AGAL
                  • A basic particle entity class
                  • Time for action – extending the entity class for particles
                  • Time for action – adding particle properties
                  • Time for action – coding the particle class constructor
                  • Time for action – cloning particles
                  • Time for action – generating numbers used for animation
                  • Time for action – simulating the particles
                  • Time for action – respawning particles
                  • Time for action – rendering particles
                  • Keyframed vertex animation shader
                  • Time for action – creating a keyframed particle vertex program
                  • Time for action – creating a static particle vertex program
                  • Time for action – creating a particle fragment program
                  • Time for action – compiling the particle shader
                  • A particle system manager class
                  • Time for action – coding a particle system manager class
                  • Time for action – defining a type of particle
                  • Time for action – simulating all particles at once
                  • Time for action – rendering all particles at once
                  • Time for action – spawning particles on demand
                  • Time for action – creating new particles if needed
                  • Keyframed particle meshes
                    • Selecting a particle texture
                  • Time for action – sculpting a single particle
                  • Time for action – sculpting a group of particles
                  • Time for action – sculpting the second keyframe
                  • Incorporating the particle system class in our game
                  • Time for action – adding particles to your game
                  • Time for action – preparing a type of particle for use
                  • Time for action – upgrading the renderScene function
                  • Time for action – adding particles to the gameStep function
                  • Time for action – keeping track of particle statistics
                  • Let's see the new particle system in action!
                  • Summary
                  • Level 8 achieved!
                  • Chapter 9: A World Filled with Action
                    • Extending the entity class for "actors"
                    • Time for action – creating a game actor class
                    • Time for action – extending the actor's properties
                    • Time for action – coding the GameActor class constructor
                    • Time for action – creating a step animation function
                    • Time for action – animating actors
                      • Implementing artificial intelligence (AI)
                    • Time for action – using timers
                    • Time for action – shooting at enemies
                    • Time for action – cloning an actor
                    • Time for action – handling an actor's death
                    • Time for action – respawning an actor
                    • Collision detection
                    • Time for action – detecting collisions
                    • Time for action – detecting sphere-to-sphere collisions
                    • Time for action – detecting bounding-box collisions
                    • An "actor reuse pool" system
                    • Time for action – creating an actor pool
                    • Time for action – defining a clone parent
                    • Time for action – animating the entire actor pool
                    • Time for action – rendering an actor pool
                    • Time for action – spawning an actor
                    • Time for action – checking for collisions between actors
                    • Restricting display to nearby actors for better framerate
                    • Time for action – hiding actors that are far away
                    • Time for action – destroying every actor in the pool
                    • Easy world creation using a map image
                    • Time for action – implementing a level parser class
                    • Time for action – spawning actors based on a map image
                    • Time for action – parsing the map image pixels
                    • Upgrading the input routines
                    • Time for action – adding more properties to the input class
                    • Time for action – handling click events
                    • Time for action – upgrading the key events
                    • Summary
                    • Level 9 achieved!
                    • Chapter 10: 3... 2... 1... ACTION!
                      • Our final quest
                      • Getting to the finish line
                      • Time for action – drawing a title screen
                      • Time for action – importing required classes
                      • Adding new variables to our game
                      • Time for action – tracking the game state
                      • Time for action – adding variables for timer-based events
                      • Time for action – adding movement related variables
                      • Time for action – keeping track of all entities
                      • Time for action – upgrading the HUD
                      • Time for action – defining variables used by Stage3D
                      • Adding art to our game
                      • Time for action – embedding our new art assets (AS3 version)
                      • Time for action – embedding our new art assets (CS5 version)
                      • Time for action – embedding all the meshes
                      • Time for action – keeping track of art assets
                      • Upgrading the final game source code
                      • Time for action – upgrading the inits
                      • Time for action – initializing Stage3D
                      • Time for action – upgrading the initGUI function
                      • Time for action – upgrading the texture inits
                      • Time for action – upgrading the shaders
                      • Time for action – defining new actor types and behaviors
                      • Time for action – initializing the terrain meshes
                      • Time for action – initializing the enemies
                      • Time for action – initializing the bullets
                      • Time for action – initializing the asteroids
                      • Time for action – initializing the space stations
                      • Time for action – initializing the particle models
                      • Time for action – creating the game level
                      • Time for action – upgrading the render loop
                      • Defining gameplay-specific events
                      • Time for action – tracking game events
                      • Time for action – handling game over
                      • Time for action – updating the score display
                      • Time for action – updating the FPS display
                      • Time for action – handling collision events
                      • Time for action – handling the player input
                      • Time for action – upgrading the gameStep function
                      • Time for action – upgrading the heartbeat function
                      • Time for action – upgrading the enterFrame function
                      • Publish... distribute... profit!
                      • Summary
                      • Level 10 achieved. Universe saved!
                      • Where to go from here?
                      • A note from the author
                      • Appendix A: AGAL Operand Reference
                        • What does one line of AGAL look like?
                        • Registers available for AGAL programs
                        • COPYING DATA
                        • ALGEBRAIC OPERANDS
                        • MATH OPERANDS
                        • TRIGONOMETRY OPERANDS
                        • CONDITIONAL OPERANDS
                        • VECTOR and MATRIX OPERANDS
                        • TEXTURE SAMPLING OPERAND

                        Christer Kaitila

                        The author of this book, Christer Kaitila, B.Sc. is a veteran video game developer with 17 years of professional experience. A hardcore gamer, dad, dungeon master, artist 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 first videogame in the eighties, long before the internet or hard drives existed. The first programming language he ever learned was 6809 assembly language, followed by BASIC, Turbo Pascal, VB, C++, Lingo, PHP, Javascript, and finally ActionScript. He grew up as an elite BBS sysop in the MS-DOS era and was an active member of the demoscene in his teens. He put himself through university by providing freelance software programming services for clients. Since then, he has been an active 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 sharp. Over the years, he has programmed puzzle games, multiplayer RPGs, action titles, shooters, racing games, chat-rooms, persistent online worlds, browser games, and many business applications for clients ranging from 3D displays for industrial devices to simulations made for engineers.

                        He is the author of the book “Adobe Flash 11 Stage3D (Molehill) Game Programming Beginner's Guide” and is the curator of a popular news website called http://www.videogamecoder.com which boasts over 30,000 articles and zero ads. He is one of the administrators of Ludum Dare, and has hosted a mini weekend jam with the theme of “all talk: dialogue and conversation”. He also created the keynote lecture for Ludum Dare 21, an 8 minute video filled with words of encouragement and advice. His client work portfolio is available at http://www.orangeview.net and his personal game development blog is http://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've ever seen.

                        Sorry, we don't have any reviews for this title yet.

                        Code Downloads

                        Download the code and support files for this book.


                        Submit Errata

                        Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.


                        Errata

                        - 2 submitted: last submission 27 Oct 2013

                        Errata type: Typo | Page number: 44

                        (new myTextureBitmapData(texture_size, texture_size);
                        should be
                        new myTextureBitmapData(textureSize, textureSize);

                         

                        Errata type: Typo | Page number: 48

                        We will continue working with the Context3DCreate function.

                        Should be:

                        We will continue working with the onContext3DCreate function.

                         

                        Errata type: Typo | Page number: 16

                        In the figure..., "A Vector3D can be used..." instead of "A Vertex3D..."

                         

                        Errata type: Typo | Page number: 21

                        Last paragraph: "enterFrame()" event instead of onFrame() event.

                         

                        Errata type: Typo | Page number: 44

                        In the first line of code the myTextureBitmapData uses the variable texture_size which is actually defined as textureSize on page 43.

                         

                        Errata type: Typo | Page number: 86

                        The correct answer to question 3 should be:

                        c. sub ft0, fc1, fco

                        if you are subtracting fc0 from fc1 as stated in the question.

                         

                        Errata type: Code | Page number: 50


                        projectionMatrix.perspectiveFieldOfViewRH(45.0, swfWidth / swfHeight, 0.01, 100.0);
                        Should be:
                        projectionMatrix.perspectiveFieldOfViewRH(45*Math.PI/180, swfWidth / swfHeight, 0.01, 100.0);

                        Sample chapters

                        You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

                        Frequently bought together

                        Adobe Flash 11 Stage3D (Molehill) Game Programming Beginner’s Guide +    Oracle Identity and Access Manager 11g for Administrators =
                        50% Off
                        the second eBook
                        Price for both: $45.60

                        Buy both these recommended eBooks together and get 50% off the cheapest eBook.

                        What you will learn from this book

                        • Animate complex 3d scenes in Flash.
                        • Initialize the Molehill graphics engine enabling hardware 3d acceleration.
                        • Overlay 2D Flash on top of your 3d scenes for beautiful user interfaces.
                        • Render splendid textures for eye-catching visuals.
                        • Upload 3D model geometry for in-game items, enemies, terrain and levels.
                        • Program incredible looking shaders in AGAL that run incredibly fast.
                        • Make your own special effects like explosions, sparks, and magic.
                        • Write event handlers and timers that control the action.
                        • Track player movements, health and the game state.
                        • Trigger game events, detect collisions, and control the game.
                        • Compile your project to a .SWF that you can put on a web page.

                        In Detail

                        Adobe’s Stage3D (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, get ready to be blown away by the hardware 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 like setting up Flash to render a simple 3d shape, each chapter presents a deeper and more complete videogame as an example project. Right 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 Molehill that has a beginning, middle, and game over.

                        As you progress further into your epic quest, you will learn all sorts of useful tricks such as ways to create eye-catching special effects using textures, special blend modes for transparent particle systems, fantastic vertex and fragment programs that are used to craft beautiful shaders and much more. You will learn how to upload the geometry of your 3D models to video RAM for ultra-fast rendering. You will dive into the magical art of AGAL shader programming. You will learn optimization tricks to achieve blazingly fast frame rate even at full screen resolutions. With each chapter, you will “level up” your game programming skills, earning the title of Molehill Master – you will be able to honestly call yourself a 3D game programmer.

                        This book is written for beginners by a veteran game developer. It will become your trusty companion filled with the knowledge you need to make your very own 3D games in Flash.

                        The sample chapter for this book (chapter 8; view the Table of Contents here) will be made available very soon. Thank you for your patience.

                        Approach

                        Written in an informal and friendly manner, the style and approach of this book will take you on an exciting adventure. Piece by piece, detailed examples help you along the way by providing real-world game code required to make a complete 3D video game. Each chapter builds upon the experience and achievements earned in the last, culminating in the ultimate prize – your game!

                        Who 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).

                        Code Download and Errata
                        Packt Anytime, Anywhere
                        Register Books
                        Print Upgrades
                        eBook Downloads
                        Video Support
                        Contact Us
                        Awards Voting Nominations Previous Winners
                        Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
                        Resources
                        Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software