Sunday, 14 October 2012

Part one
Reading Foundation Games Design with ActionScript 3.0 Second Edition
Rex Van Der Spuy

All following information was referenced from the book Van Der Spy, Rex.(2012) Foundation Games Design with ActionScript 3.0 Second Edition friendsof

Note if you are looking for something in particular within this blog to use ctrl + F to locate the keyword that you are looking for.

Notes

Chapter 1: Programming Foundations: How to make a video game

Programs that will be covered in this blog:


Free Alternative
 GNU Image Manipulation Program (Gimpshop) www.gimpshop.com

Programming Software


Free Alternative
Flash Develop www.flashdevelop.org

Combination program combining both graphic production and programming code

Photoshop tutorials Google search "Photoshop tutorials for beginners"

Other recommended books for a deeper understanding of the maths side are 

Foundation ActionScript Animation: Making Things Move! by Keith Peters
Flash Math Creativity by various authors

When Starting a new project in FB you select File - New - ActionScript Project
Name your project sensibly and with no spaces. You can change the default location where flash saves your work to. 

To ensure Flash builder opens up your flash files in FB without going into browser then click project at the top then go properties. Once you have done that select ActionScript Compiler the uncheck the box Generate HTML wrapper file located near the bottom under the section labelled HTML wrapper.

The left hand section of the program is the package explorer which shows a view of the files you are using.creating with FB

AS3 Package

A package is a building block for AS3 which consists of 3 parts

Keyword - Identified as purple or blue in FB They are words AS3 understands to do a job

Identifier - A name for the package

Curly braces - They keep whatever is inside them together {}

The library
Library is part of something called the Flex SDK

Flex SDK
SDK is made up of stacks which contain all the core computer code that make flash work. FB or any other flash development program are just a UI for interacting with SDK.

It is wise to keep the SDK updated


Sprites
 Sprites are contained in the AS3 library which is a collection of computer code. It is automatically installed when installing FB. The computer code is all conveniently there for you to use in your programs.

Sprites themselves are made of bits of computer code and they display text and graphics. Sprites are located in the display section which itself is located in a bigger section flash of the library. An example of using it in code would be 

flash.display.Sprite;            (note sprite is capitalised )

The dots between the words represent a section of the library. So the sprite is part of the display section and that in turn is part of the flash section. 

Block Statement
Block statements define a section of the program and groups together all the code between the curly braces


import keyword

import keyword is used to pull the code out of the library into you program. an example would be

import.flash.display.sprite;

The semicolon ;
The semicolon is basically a do what I just told you command.

Code Spacing
Indented code between the brackets is indented to show that the code you just typed is inside the packages curly brackets.

public keyword
public means the following information is available to all classes for example that are part of the same package or any other packages your program is using. So the following information is freely available to all.

internal keyword
Any information you do not want available to other classes for example outside of its current package

extends keyword
allows the previous class to use the help of another class to complete its function


AS3 Class/ Class Definition
All AS programs written must contain one class. A class definition will also have a pair of curly braces and is a block statement itself and is representing the code in its curly braces. A class definition does three main things. The class will contain most of your ptograms code

It creates a class. This is represented by the keyword "class" which tells flash you are creating a class

The definition gives the class some rules to follow for example "public" which states that all the information within this class can be shared by any other classes that are part of the same package or any other packages your program is using.

Thirdly you need an identifier which can be any name you choose. However it has to be saved in a file with an identical name to the class name. For every new class you create a new AS file must created that shares the same name as the class.



A scan from the reference book showing roughly the breakdown of a class that uses another class to complete its task. 

While doing these notes I am also putting it into practice which is very well guided in this book
Open picture in new tab if it you cant clearly read it what is in green is only comments and not part of the code. See then as reading in-between the line so to speak. So if they weren't there then there would be no space between the code.

constructor method
All classes need constructor methods to run as  they are basically essential components which have their own block statement. Any code it has runs instantly. As mentioned in the book the constructor method is the heart and lungs of the class and a class wont work without one. So as soon as the class is called upon the constructor method gets it going. It also needs to be named EXACTLY the same as the class name. The constructor method will always be the first function definition you write when creating a class. Also constructor methods can only be public.

function keyword(function definition) 
functions are block statements themselves that perform all the actions. They do all the work in your program.  They basically sit there until called upon when they will complete a predesignated task (function) A function definition should always end with a parentheses even if they are left empty.

parentheses()
Allows you to set information or parameters. They are usually located at the end. 

methods in AS3 are made up of directives.

trace (keyword) method
Tells flash to display whatever is in the parentheses to the FB console window when you debug your program. What text you want displayed also need to be surrounded by quotation marks

Debugging
Access the debugger by clicking the green beetle icon at the top of the screen. Your program will then be compiled by the piece of previously mentioned software the Flex SDK. SDK will take all your code then convert it into an SWF file which is the file type that is run by flash player. While doing this you code will also be checked for any errors. Now in the project directory the compiler should have created you a bin-debug folder which give a wide range of helpful information consisting of a .html file which is used with other files for people to be able to use your program over the web. swfObject.js this imbeds the swf file into the html and also checks that the user has flash player installed to use the program. playerProductinstall.swf This is a flash application that prompts any user to download and install the current version of flash player if they dont have or the current version isnt compatible with the game. History which contains its own specialised code that allows your program to be navigated by a browsers forward and back buttons.

Example of all talked about information

syntax error
If you get a syntax error when compiling then it means there is code there that AS3 doesn't understand.

Questions to ask yourself if you have errors

Is everything spelt correctly and in the correct case?

Did you save the files in the correct location, and do the spelling and case of your folders and files match the package and class names? (This generally isn't a problem if you're using Flash Builder, which does these things for you automatically, but it could be with another IDE)
Are all your AS3 keywords(such as import, package and function) a blue or purple colour? if one of them isn't then it is a clear indication that you have spelt it or capitalized it incorrectly.

Have you closed all your curly braces and parentheses?

Pointers solving errors

Always solve the first error first. It more than likely is causing all the following errors

Check just before the error indicator as the error can be located just before where flash says.

Always save the as file after a fix!

Only make a single change each time you debug for easy identification if more errors pop up.

Test early, test often!!

Example of errors 


If for example you do not get any errors however the program is still not running the way it should then you will need to perform a clean compile that is done by selceting project > clean

Creating a release build of your program
In flash you can create what is called a release build of your program. Now the reason the file is smaller is that it doesnt contain any of the debugging information and should be the final version of your program before release.

To do this you select project > Export release build once you have confirmed the following screens you should see a new folder in the package explorer window called bin-release folder.

Naming Conventions
In AS3 camel case is used for coding and writing compound phrases, it stops the use of spaces. There are two types of camel case and they are

lower camel case startsWithLowerCaseLetter this is used for package names, variable, methods and instances.

Upper camal case StartsWithUpperCaseLetter. You will use this for class names and constructor method names. You'll also be naming your as files this way as mentioned before they will share the same names as your class files.

Part two after this


No comments:

Post a Comment