Here's a quick tutorial on dragging and dropping DOs in AS3.
That is all.
Wednesday, January 30, 2008
Tuesday, January 29, 2008
Chase the Dragon
Dragoneye1.addEventListener(MouseEvent.CLICK, clickEye);
Dragoneye1.addEventListener(MouseEvent.MOUSE_UP, eyeMouseUp);
var eyecount:uint = 1;
var shrinkcount:int = 9;
function eyeMouseUp(event:MouseEvent) {
Dragoneye1.rotation += (eyecount*10);
if (shrinkcount > 0) {
Dragoneye1.scaleX = (shrinkcount*10)/100 +.1;
Dragoneye1.scaleY = (shrinkcount*10)/100 +.1;
Dragonhead1.rotation -= .1;
shrinkcount -= 1;
} else if (shrinkcount == 0) {
Dragoneye1.scaleX = .1;
Dragoneye1.scaleY = .1;
Dragonhead1.rotation -= .1;
shrinkcount -= 1;
} else if ((shrinkcount > -11)&&(shrinkcount < 0)) {
Dragoneye1.scaleX = (shrinkcount * -10)/100 +.1;
Dragoneye1.scaleY = (shrinkcount * -10)/100 +.1;
Dragonhead1.rotation += .1;
shrinkcount -= 1;
} else {
shrinkcount = 10;
}
}
function clickEye(event:MouseEvent) {
if ((eyecount == 1)||(eyecount == 2)) {
trace("Poke.");
} else if (eyecount == 3) {
trace("Pooooooke.");
} else {
trace("Poke!");
eyecount = 0;
}
eyecount += 1;
}
This is a little script that plays with rotating and scaling DOs using a couple of different user interactions (really the same one- a mouse click- but CLICK is different from MOUSE_UP in theory). So, yes: using graphics, moving graphics, using mouse clicks: check.
I love the .rotation property that's built into... well, every display object, at least. Simple, fast, and easily-modified! Logic is fun.
Next up: buttons.
Dragoneye1.addEventListener(MouseEvent.MOUSE_UP, eyeMouseUp);
var eyecount:uint = 1;
var shrinkcount:int = 9;
function eyeMouseUp(event:MouseEvent) {
Dragoneye1.rotation += (eyecount*10);
if (shrinkcount > 0) {
Dragoneye1.scaleX = (shrinkcount*10)/100 +.1;
Dragoneye1.scaleY = (shrinkcount*10)/100 +.1;
Dragonhead1.rotation -= .1;
shrinkcount -= 1;
} else if (shrinkcount == 0) {
Dragoneye1.scaleX = .1;
Dragoneye1.scaleY = .1;
Dragonhead1.rotation -= .1;
shrinkcount -= 1;
} else if ((shrinkcount > -11)&&(shrinkcount < 0)) {
Dragoneye1.scaleX = (shrinkcount * -10)/100 +.1;
Dragoneye1.scaleY = (shrinkcount * -10)/100 +.1;
Dragonhead1.rotation += .1;
shrinkcount -= 1;
} else {
shrinkcount = 10;
}
}
function clickEye(event:MouseEvent) {
if ((eyecount == 1)||(eyecount == 2)) {
trace("Poke.");
} else if (eyecount == 3) {
trace("Pooooooke.");
} else {
trace("Poke!");
eyecount = 0;
}
eyecount += 1;
}
This is a little script that plays with rotating and scaling DOs using a couple of different user interactions (really the same one- a mouse click- but CLICK is different from MOUSE_UP in theory). So, yes: using graphics, moving graphics, using mouse clicks: check.
I love the .rotation property that's built into... well, every display object, at least. Simple, fast, and easily-modified! Logic is fun.
Next up: buttons.
Spawning Graphical Elements(!)
var Dragonhead1:Dragonhead = new Dragonhead();
Dragonhead1.x = 280;
Dragonhead1.y = 200;
Dragonhead1.rotation = 0;
addChild(Dragonhead1);
var Dragoneye1:Dragoneye = new Dragoneye();
Dragoneye1.x = 402;
Dragoneye1.y = 160;
Dragoneye1.rotation = 0;
addChild(Dragoneye1);
for (var i=1;i<20;i++) {
var eye:Dragoneye = new Dragoneye();
eye.x = 50*i+50;
eye.y = 50*i+50;
eye.scaleX = (i/5);
eye.scaleY = (i/5);
addChild(eye);
}
Lots of new stuff here:
Now that I've made a couple of "movie clips" (really just sprites at this point) to work with, I can start a little bit on the non-absolute-basic stuff.
"var Dragonhead1:Dragonhead = new Dragonhead();" creates a new instance of one of my graphics. The next two lines tell it where to appear on the stage, and the last places it. (So, to set or change the placement of an object, use the .x and .y properties of the object.) Rotation is another handy property, as is .scaleX/Y - they allow me to change the size of the graphic on-the-fly (yay for vector graphics!).
I probably should have spent less time on the graphics, but at least they look pretty.
Dragonhead1.x = 280;
Dragonhead1.y = 200;
Dragonhead1.rotation = 0;
addChild(Dragonhead1);
var Dragoneye1:Dragoneye = new Dragoneye();
Dragoneye1.x = 402;
Dragoneye1.y = 160;
Dragoneye1.rotation = 0;
addChild(Dragoneye1);
for (var i=1;i<20;i++) {
var eye:Dragoneye = new Dragoneye();
eye.x = 50*i+50;
eye.y = 50*i+50;
eye.scaleX = (i/5);
eye.scaleY = (i/5);
addChild(eye);
}
Lots of new stuff here:
Now that I've made a couple of "movie clips" (really just sprites at this point) to work with, I can start a little bit on the non-absolute-basic stuff.
"var Dragonhead1:Dragonhead = new Dragonhead();" creates a new instance of one of my graphics. The next two lines tell it where to appear on the stage, and the last places it. (So, to set or change the placement of an object, use the .x and .y properties of the object.) Rotation is another handy property, as is .scaleX/Y - they allow me to change the size of the graphic on-the-fly (yay for vector graphics!).
I probably should have spent less time on the graphics, but at least they look pretty.
Special Ops
++ increments positively,
-- increments negatively,
+=, -+, *=, and /= all perform their respective operations on the original variable.
Example: "VARIABLE /= 88;" divides VARIABLE by 88.
String variables can be added to with the + and += operators (to make bigger strings).
That'll be useful once this book finally starts talking about user input(!).
-- increments negatively,
+=, -+, *=, and /= all perform their respective operations on the original variable.
Example: "VARIABLE /= 88;" divides VARIABLE by 88.
String variables can be added to with the + and += operators (to make bigger strings).
That'll be useful once this book finally starts talking about user input(!).
Variables 1
You can call a variable using something like "var VARIABLE = 13", and it can then be used to store whatever the hell you want. Sloppy. Assigning types to the variable, like "var VARIABLE:int = 13", constrains the content of the variable. Using smaller types (int, Boolean, uint) is more efficient than using larger types (Number, etc.).
Types:
int = integers
uint = positive integers
Number = floating point numbers (fractions)
String = text
Boolean = bools (true/false values)
You can also put in arrays, sprites, movie clips, and custom types.
Types:
int = integers
uint = positive integers
Number = floating point numbers (fractions)
String = text
Boolean = bools (true/false values)
You can also put in arrays, sprites, movie clips, and custom types.
Quick Notes on Display Objects
Display objects are graphic elements.
They may contain other display objects (for example, one "sprite" can contain all of the sprites you want, plus other kinds of display elements). Nesting DOs like this is useful because they are then easily-organized.
ActionScript 3 lets us use a display list with nested DOs, which allows us to move around their display order (on the Z plane, that is; not X, Y, or In Time). DOs can be moved from one parent DO's display list to another's.
Also, and this is somewhat unrelated, but very important, frames and keyframes are not used extensively in Flash game programming, nor in the same way, as in animation. They are used to organize the different elements and screens of the game, and determine which elements of the game (such as score) carry through to different screens. IMPORTANT.
They may contain other display objects (for example, one "sprite" can contain all of the sprites you want, plus other kinds of display elements). Nesting DOs like this is useful because they are then easily-organized.
ActionScript 3 lets us use a display list with nested DOs, which allows us to move around their display order (on the Z plane, that is; not X, Y, or In Time). DOs can be moved from one parent DO's display list to another's.
Also, and this is somewhat unrelated, but very important, frames and keyframes are not used extensively in Flash game programming, nor in the same way, as in animation. They are used to organize the different elements and screens of the game, and determine which elements of the game (such as score) carry through to different screens. IMPORTANT.
Classes in Session
How to make classes in Flash (in an external ActionScript file):
package {
import flash.display.*;
import flash.text.*;
public class HelloWorld extends MovieClip {
public function HelloWorld() {
var rollinText:TextField = new TextField();
rollinText.text = "Hello, World. I am a part of you.";
addChild(rollinText);
}
}
}
Okay, so this is a lot of knowledge here. Previous OOP experience required (maybe).
This is an external ActionScript file, not a movie. package tells Flash that the file is a package containing a class. The next two lines call other built-in classes (flash.display and flash.text) so that we may call upon their powers to assist us.
Then there's the new class definition. public tells Flash that the class is public (obviously) and can be called on from wherever in the code you want. "extends MovieClip" lets the class work with a movie clip (the Flash stage).
Then, inside the class, there is a single function, named the same as the class. This is important because it makes the function the class's constructor function - the function will run as soon as the class is initialized. Hmm. The function is the Hello World function from before, which just creates a TextField, puts some text in it, and displays the text on the stage.
Okay, sweet. So now I know how to make an external class in Flash and call it in a Flash movie clip. The actual clip was completely empty- it just had a link to the class, basically, and the class just had a constructor function, so it was like bam bam bam. Now I need to learn... a whole bunch more stuff! Onward!
package {
import flash.display.*;
import flash.text.*;
public class HelloWorld extends MovieClip {
public function HelloWorld() {
var rollinText:TextField = new TextField();
rollinText.text = "Hello, World. I am a part of you.";
addChild(rollinText);
}
}
}
Okay, so this is a lot of knowledge here. Previous OOP experience required (maybe).
This is an external ActionScript file, not a movie. package tells Flash that the file is a package containing a class. The next two lines call other built-in classes (flash.display and flash.text) so that we may call upon their powers to assist us.
Then there's the new class definition. public tells Flash that the class is public (obviously) and can be called on from wherever in the code you want. "extends MovieClip" lets the class work with a movie clip (the Flash stage).
Then, inside the class, there is a single function, named the same as the class. This is important because it makes the function the class's constructor function - the function will run as soon as the class is initialized. Hmm. The function is the Hello World function from before, which just creates a TextField, puts some text in it, and displays the text on the stage.
Okay, sweet. So now I know how to make an external class in Flash and call it in a Flash movie clip. The actual clip was completely empty- it just had a link to the class, basically, and the class just had a constructor function, so it was like bam bam bam. Now I need to learn... a whole bunch more stuff! Onward!
Hello World
First program was a Hello World.
Commands learned:
trace("anytext"); - Outputs a line of text, where anytext = whatever you want to output. Note that this does not actually display text in a Flash movie- just in the output box. For debugging.
Here's the code for a Hello World in Flash:
var rollinText:TextField = new TextField();
rollinText.text = "Hello World. I am a part of you!";
addChild(rollinText);
What this does, in order, is call a new variable (var) named rollinText as a TextField (which is an object that displays text on the Flash stage). Not sure yet why there are two parts to the declaration process (the :TextField part and the = new TextField() part).
Next, it assigns the text property of the TextField. (That's what the ".text =" means. The stuff in quotes after it is the text I want to display onscreen.)
Finally, it adds the TextField object to the stage with the addChild command.
When I tested it, the stage didn't display my whole text- I had to scroll it. Tried to play around with some functions I didn't know about to fix it, then decided to put it off 'til later.
Commands learned:
trace("anytext"); - Outputs a line of text, where anytext = whatever you want to output. Note that this does not actually display text in a Flash movie- just in the output box. For debugging.
Here's the code for a Hello World in Flash:
var rollinText:TextField = new TextField();
rollinText.text = "Hello World. I am a part of you!";
addChild(rollinText);
What this does, in order, is call a new variable (var) named rollinText as a TextField (which is an object that displays text on the Flash stage). Not sure yet why there are two parts to the declaration process (the :TextField part and the = new TextField() part).
Next, it assigns the text property of the TextField. (That's what the ".text =" means. The stuff in quotes after it is the text I want to display onscreen.)
Finally, it adds the TextField object to the stage with the addChild command.
When I tested it, the stage didn't display my whole text- I had to scroll it. Tried to play around with some functions I didn't know about to fix it, then decided to put it off 'til later.
Ready Go
I've received ActionScript 3.0 Game Programming University in the mail, so I'm going to start plowing through it and posting notes here.
Thursday, January 24, 2008
Flash Games of Note
Got to start somewhere. I think it's important to acknowledge what others have done before me, and learn from them- figure out the capabilities of the medium, that sort of thing.
In this spirit, I've done a bit of "research" into current Flash games (the first batch of many, I'm certain).
Notable:
Makibishi Comic - It's got a wonderful graphic style, and fleshed-out sound. I'd like to learn how to create those parallax backgrounds.
Four Second Frenzy - Well this is just fun. What better example of game design than a Wario-Ware type Flash collection? The variety of different control methods, all using the same few keys (arrows and space bar) is something to think about.
Areas and Filler both use simple shapes (and their resizing) to great effect. Filler is basically an interesting take on Jezzball, while Areas is an Asteroids clone that manages, somehow, to convey creeping doom through a weird soundtrack and a series of mysteriously-expanding circles.
Dupligon is a puzzle from the standpoint of a newbie trying to recreate it. In it, the player is given a shape, then told to draw it (with vertices) from memory. The size and orientation of the new shape don't matter, when comparing it to the old, just the angles... So I'm guessing it 1. finds the coordinates of the vertices, 2. calculates the lines between them, 3. finds the inclusive angles (trig!), and 4. compares them to the original shape's angles. Hmm.
Travian is an example of a massively-multiplayer Flash strategy game (which I one day aspire to create). Players build up their little villages and pillage/trade with other players. Unfortunately, it plays out in "real time" and is therefore kind of boring to get going in. That is something to think about- if a strategy game is both massively-multiplayer and turn-based, does each player have to wait for all of the others before making their next move? (Obviously, that would be really annoying, if not impossible... what to do?)
General Idea (for a massively-multiplayer strategy game): Players can choose to "lay out" their next few moves. The timer runs, and the database takes turns for the players in their absence. This would mean that players wouldn't have to be at their computers, waiting for the timer for their next turn to count down... but doing so might give players a (well-earned) strategic advantage.
In this spirit, I've done a bit of "research" into current Flash games (the first batch of many, I'm certain).
Notable:
Makibishi Comic - It's got a wonderful graphic style, and fleshed-out sound. I'd like to learn how to create those parallax backgrounds.
Four Second Frenzy - Well this is just fun. What better example of game design than a Wario-Ware type Flash collection? The variety of different control methods, all using the same few keys (arrows and space bar) is something to think about.
Areas and Filler both use simple shapes (and their resizing) to great effect. Filler is basically an interesting take on Jezzball, while Areas is an Asteroids clone that manages, somehow, to convey creeping doom through a weird soundtrack and a series of mysteriously-expanding circles.
Dupligon is a puzzle from the standpoint of a newbie trying to recreate it. In it, the player is given a shape, then told to draw it (with vertices) from memory. The size and orientation of the new shape don't matter, when comparing it to the old, just the angles... So I'm guessing it 1. finds the coordinates of the vertices, 2. calculates the lines between them, 3. finds the inclusive angles (trig!), and 4. compares them to the original shape's angles. Hmm.
Travian is an example of a massively-multiplayer Flash strategy game (which I one day aspire to create). Players build up their little villages and pillage/trade with other players. Unfortunately, it plays out in "real time" and is therefore kind of boring to get going in. That is something to think about- if a strategy game is both massively-multiplayer and turn-based, does each player have to wait for all of the others before making their next move? (Obviously, that would be really annoying, if not impossible... what to do?)
General Idea (for a massively-multiplayer strategy game): Players can choose to "lay out" their next few moves. The timer runs, and the database takes turns for the players in their absence. This would mean that players wouldn't have to be at their computers, waiting for the timer for their next turn to count down... but doing so might give players a (well-earned) strategic advantage.
Right-o: Mission Statement!
Hello. My name is Rollin. I want to learn Flash this semester- not just animation and such, but Actionscripting 3.0 and all the fun that comes with.
This blog will be an account of my journey.
You will find here my notes, works-in-progress, a journal of my trials and tribulations, and links to intriguing examples of and references for Flash I find along the way.
My first mission: create a static button that starts an animation, which then loops back to the stasis from whence it came. My tools: the Internet, as the two references I've ordered (ActionScript 3.0 Game Programming University and Flash CS3 Professional for Windows and Macintosh (Visual QuickStart Guide)) have not yet arrived, as well as Flash CS3 (of course).
Stay tuned.
This blog will be an account of my journey.
You will find here my notes, works-in-progress, a journal of my trials and tribulations, and links to intriguing examples of and references for Flash I find along the way.
My first mission: create a static button that starts an animation, which then loops back to the stasis from whence it came. My tools: the Internet, as the two references I've ordered (ActionScript 3.0 Game Programming University and Flash CS3 Professional for Windows and Macintosh (Visual QuickStart Guide)) have not yet arrived, as well as Flash CS3 (of course).
Stay tuned.
Subscribe to:
Posts (Atom)