Read Foundation Game Design with ActionScript 3.0, Second Edition Online
Authors: Rex van der Spuy
Foundation Game Design with ActionScript 3.0, Second Edition
Copyright © 2012 by Rex van der Spuy
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or
mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior
written permission of the copyright owner and the publisher
ISBN-13 (pbk): 978-1-4302-3993-2
ISBN-13 (electronic): 978-1-4302-3994-9
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every
occurrence of a trademarked name, logos, or image we use the names, logos, or images only in an editorial fashion and
to the benefit of the trademark owner, with no intention of infringement of the trademark.
The use in this publication of trade names, service marks, and similar terms, even if they are not identified as such, is
not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights.
Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor,
New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail[email protected]
, or visitwww.springeronline.com
.
For information on translations, please e-mail[email protected]
or visitwww.apress.com
.
Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions
and licenses are also available for most titles. For more information, reference our Special Bulk Sales–eBook Licensing web page atwww.apress.com/bulk-sales
.
The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been
taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with
respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in the
work.
Any source code or other supplementary materials referenced by the author in this text is available to readers at
www.apress.com
. For detailed information about how to locate your book's source code, go towww.apress.com/source-code/
.
Credits
President and Publisher: Paul Manning Lead Editor: Ben Renow-Clarke Technical Reviewers: Joshua Freeney Editorial Board: Steve Anglin, Mark Beckner, Ewan Buckingham, Gary Cornell, Morgan Ertel, Jonathan Gennick, Jonathan Hassell, Robert Hutchinson, Michelle Lowman, James Markham, Matthew Moodie, Jeff Olson, Jeffrey Pepper, Douglas Pundick, Ben Renow-Clarke, Dominic Shakeshaft, Gwenan Spearing, Matt Wade, Tom Welsh Coordinating Editor: Kelly Moritz | Copy Editor: Mary Behr Compositor: Apress (Brigid Duffy) Production Editor: Brigid Duffy Indexer: BIM Indexing & Proofreading Services Artist: SPi Global Cover Image Artist: Corné van Dooren Cover Designer: Anna Ishchenko |
Dedicated to my father, Mani van der Spuy,
without whom this book would not have been written.
Thanks, Dad, for always believing in me.
About the Cover Image Designer
Chapter 1: Programming Foundations: How To Make A Video Game
3. Computer programming software
And the things you don't need to know
Programming? But I'm terrible at math!
I already know how to program!
What kind of games can I make?
Setting up the work environment in Flash Builder
ActionScript files and the .as file extension
Running your program and compiling the SWF file
What happened when you compiled the program
Confirm your program with the original source files
Editing window quirks and features
A little more about AS3.0 and the Flash Player
Chapter 2: Making Game Graphics
Create a game world background
Create a new file in Photoshop
Duplicating, modifying, and arranging layers
Making boxes with the rectangular selection tool
Save your work and make the PNG files
Chapter 3: Programming Objects
But I'm a bit scared of programming!
Setting up a new AS3.0 project
Set up the Flash Player with a metadata tag
Loading and displaying the background.png image
Creating instances and objects
Displaying the image on the stage
Understanding the code structure
Positioning Sprites on the stage
Understanding events and event listeners
Controlling Sprite objects with properties
Using increment and decrement operators
The classes you have to import
Creating TextFormat and TextField objects
Configuring and displaying the output text
Configuring and displaying the input field
Building a simple guessing game
Understanding the program structure
Using postfix operators to change variable values by one
Hey, why use the gameStatus variable, anyway?
Modular programming with methods
Loading the images and displaying the button
Understanding the mouse events
Adding the button to the number guessing game
Disabling the button at the end of the game
A quick guide to embedding fonts
Chapter 5: Controlling A Player Character
Controlling a player character with the keyboard
Controlling with the keyboard'the wrong way!
Controlling the keyboard'the right way!
Blocking movement at the stage edges
Chapter 6: Bumping Into Things
Basic collision detection with hitTestObject
Using scaleX to scale the meter based on a percentage
Picking up and dropping objects
The bad news about hitTestObject
Detecting collisions with the bounding box
Advanced collision detection strategies
Working with vector based collision detection
Preventing objects from overlapping
Programming with the Collision class
Another look at methods, arguments, and parameters
Taking a look at the Collision.block method
Looking at the TimeBombPanic application class
Collisions between the character and the boxes
Creating a scrolling game environment
Preparing your artwork for scrolling
Scrolling and stage boundaries
Chapter 8: Making Bigger Games
Understanding the game structure
Using private variables and methods
Giving LevelOne access to the stage
Making sure that LevelOne is actually on the stage
Programming the game character
Checking for the end of the level
Using removeChild to completely get rid of objects
Communicating between classes by dispatching events
Firing stars in four directions in level two
Moving objects in a scrolling game world
A little more about game structure
Chapter 9: Physics, Loops, Arrays, and Sounds
A game object class for playing with physics
Integrating sound effects in a game
Looping music and setting volume and pan levels
Chapter 10: Advanced Object And Character Control
Fixing an object to the mouse's position
Case study: Firing projectiles in all directions
Rotating the wand around the fairy
Advanced player control systems
Rotating and shooting toward the mouse
Case study: Killer Bee Pandemonium!