AdvancED_ActionScript3.0_Animation.pdf

(4451 KB) Pobierz
99118800 UNPDF
AdvancED ActionScript 3.0
Animation
Keith Peters
99118800.001.png
AdvancED ActionScript 3.0 Animation
Copyright © 2009 by Keith Peters
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-1608-7
ISBN-13 (electronic): 978-1-4302-1608-7
Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1
Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name,
we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the
trademark.
Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor, New York, NY 10013.
Phone 1-800-SPRINGER, fax 201-348-4505, e-mail kn`ano)ju<olnejcan)o^i*_ki , or visit sss*olnejcankjheja*_ki .
For information on translations, please contact Apress directly at 2855 Telegraph Avenue, Suite 600, Berkeley, CA 94705.
Phone 510-549-5930, fax 510-549-5939, e-mail ejbk<]lnaoo*_ki , or visit sss*]lnaoo*_ki .
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 at
dppl6++sss*]lnaoo*_ki+ejbk+^qhgo]hao .
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 this work.
The source code for this book is freely available to readers at sss*bneaj`okba`*_ki in the Downloads section.
Credits
Lead Editor
Ben Renow-Clarke
Production Editor
Janet Vail
Technical Reviewer
Seb Lee-Delisle
Compositor
Lynn LHeureux
Editorial Board
Clay Andres, Steve Anglin, Mark Beckner,
Ewan Buckingham, Tony Campbell,
Gary Cornell, Jonathan Gennick,
Michelle Lowman, Matthew Moodie,
Jeffrey Pepper, Frank Pohlmann,
Ben Renow-Clarke, Dominic Shakeshaft,
Matt Wade, Tom Welsh
Proofreader
Nancy Bell
Indexer
Carol Burbo
Artist
Kinetic Publishing Services, LLC
Project Manager
Sofia Marchant
Cover Image Designer
Bruce Tang
Copy Editor
Nancy Sixsmith
Interior and Cover Designer
Kurt Krames
Associate Production Director
Kari Brooks-Copony
Manufacturing Director
Tom Debolski
To Miranda and Kristine, for their patience and support,
once again.
CONTENTS AT A GLANCE
About the Author .......................................................... xiii
About the Technical Reviewer ........................................... xv
About the Cover Image Designer ...................................... xvii
Acknowledgments ........................................................ xix
Chapter 1 Advanced Collision Detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Chapter 2 Steering Behaviors ............................................ 49
Chapter 3 Isometric Projection ........................................... 99
Chapter 4 Pathfinding .................................................... 155
Chapter 5 Alternate Input: The Camera and Microphone ........... 197
Chapter 6 Advanced Physics: Numerical Integration ................. 237
Chapter 7 3D in Flash 10 ................................................. 275
Chapter 8 Flash 10 Drawing API ......................................... 311
Chapter 9 Pixel Bender ................................................... 359
Chapter 10 Tween Engines ............................................... 399
Index ....................................................................... 440
v
99118800.002.png
CONTENTS
About the Author .......................................................... xiii
About the Technical Reviewer ........................................... xv
About the Cover Image Designer ...................................... xvii
Acknowledgments ........................................................ xix
Chapter 1 Advanced Collision Detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Hit Testing Irregularly Shaped Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Bitmaps for collision detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5
Hit testing with semitransparent shapes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Using BitmapData.hitTest for nonbitmaps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Hit Testing with a Large Number of Objects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Implementing grid-based collision detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Coding the grid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Testing and tuning the grid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .28
Making it a reusable class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Using the class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Collision detection: Not just for collisions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Chapter 2 Steering Behaviors ............................................ 49
Behaviors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Vector2D Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Vehicle Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
SteeredVehicle Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Seek behavior. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Flee behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Arrive behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Pursue behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Evade behavior. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Wander behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Object avoidance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Path following . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Flocking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
vii
99118800.003.png
Zgłoś jeśli naruszono regulamin