Free Sample
+ Collection

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

Beginner's Guide
Christer Kaitila

A step-by-step guide for creating stunning 3D games in Flash 11 Stage3D (Molehill) using AS3 and AGAL with this book and ebook.
$29.99
$49.99
RRP $29.99
RRP $49.99
eBook
Print + eBook

Want this title & more?

$16.99 p/month

Subscribe to PacktLib

Enjoy full and instant access to over 2000 books and videos – you’ll find everything you need to stay ahead of the curve and make sure you can always get the job done.

Book Details

ISBN 139781849691680
Paperback412 pages

About This Book

  • 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

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

Table of Contents

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
Common 3D coding terms
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
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
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
The entire source code
Summary
Level 3 achieved!
Chapter 4: Basic Shaders: I can see Something!
AGAL: Adobe Graphics Assembly Language
A basic AGAL shader example
Time for action – writing your first vertex 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
Summary
Level 4 achieved!
Chapter 5: Building a 3D World
Creating vertex buffers
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
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
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
Time for action – updating UV coordinates each frame
Render states
Time for action – rendering a mesh's backfaces
Time for action – making a mesh not affect the zbuffer
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
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
Making our game more interactive
Time for action – adding a GUI overlay
Time for action – creating the game timer class
Time for action – adding the GameTimer class constructor
Time for action – implementing the tick function
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
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
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
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
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

What You Will Learn

  • 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.

Authors

Read More