Game Examples AS3
Player Movement with Velocity
Expending on the previous space shooter example, I’ve added velocity to player movement.
AS3 Basics - Naming Conventions
Use precise, meaningful, contextually relevant names that are as descriptive as possible. Limit the use of unnecessary abbreviations.
- Example: defaultImagePreview
NOT: dfltImgPrv
Start each instance name with a lowercase letter, and intercap the remaining words.
- Examples: menuItem, sectionTitle
Apply the same conventions to variable names.
- Examples: accountNumber, startingPoint, currentProductName
Begin a class name with an uppercase letter. Write class names in mixed case when it’s a compound or concatenated word. Keep package names as short as possible, using reverse domain naming conventions.
- Examples: com.client.project.component.ClassName
Name functions and methods in the form of verbs, since they perform actions.
- Examples: getUserName(), calculateTaxes(), createSubMenu()
Name booleans with an appropriate, positive prefix, such as “is”, “has”, “can”, or “should”, for an easier determination between true and false.
- Examples: isSoundOn, isFinished, isOpen, isLoggedIn, hasLicense, canEvaluate
Use complement names for complement entities: get/set, add/remove, create/destroy, start/stop, insert/delete, increment/decrement, old/new, begin/end, first/last, up/down, min/max, next/previous, open/close, show/hide.
- Examples: getUserName, setUserName
addThumbnailImage, removeThumbnailImage
showAnimation, hideAnimation
Private variable names may be prefixed with an underscore or $ symbol as long as consistency is maintained.
Key Press detection & onEnterFrame in AS3
We’re going to make this little asteroid-clone space shooter for AS3 beginners.
It has the basic key press detection (listeners) and an AS3 version of onEnterFrame. We are however going to use classes and packages. Don’t be scared, it’s not complicated.
AS2 to AS3: What software to use
Going from using ActionScript 2.0 to ActionScript 3.0 can get tricky. The full switch takes time (and sometimes a few tries), but it’s well worth it.
The first step you want to take in going from AS2 to AS3 is to stop putting code on the timeline. It sounds scary at first, but it’s really simple (more on that later) and it has many great benefits.
One of those benefits is being able to use a different program to edit your code. Flash is great, but it’s built-in actionscript editor is pretty weak.
There are a lot of great, free code editing programs out there in which you can edit both AS2 and AS3.
I like using Flash Develop with Flash CS4. There is also Flash FTD and Eclipse (you’ll need to download Eclipse for PHP Developers and get the actionscript 3 plugin).
You can still use Flash CS3/CS4 to edit your graphics, sounds, layouts and code if you want.
I suggest downloading one of these programs and getting familiar with them. Open one of your existing projects and try editing your code in those programs. The code hints, auto completion, formatting, and much, much, more is better than Flash’s code editing window.
Next update will have less text and more hands-on stuff.
CategoriesLinks |