Hey, Big Boo here. I'm putting together an RPG game, so I figured I
might as well put together a tutorial too! Lets get started then.
First,
make a movie clip of a character standing, and a movie clip of a character moving, like this:
I'm using Circle Man here. You just got a spoiler
for my RPG game!
Next, make a movie clip and name it whatever
you want. On the first frame, add the movie clip of the character
standing. Then add 3 key frames. Make a blank key frame and on it put
the movie clip of the character walking, then make 3 more key frames. On
the first and fifth frames, make the character face up. On the second
and sixth frames, make the character face down. On the third and seventh
frames, make the character face right. And on the fourth and eigth
frames, make the character face left. Go back to the main stage and put
the movie clip with those 8 frames on it and give it the instance name
"player" without the quotation marks. Then click the player, open the
actions panel (or press F9 if you're using Flash 8 like I am), and paste
the following frames into the actions panel.
onClipEvent(load){
speed=8;//sets a variable named
speed
}
onClipEvent(enterFrame){
if(Key.isDown(Key.UP)){
this._y-=speed;
this.gotoAndStop(5);//tells
flash to change frame when the up key is pressed
}
if(Key.isDown(Key.DOWN)){
this._y+=speed;
this.gotoAndStop(6);//tells
flash to change frame when the down key is pressed
}
if(Key.isDown(Key.RIGHT)){
this._x+=speed;
this.gotoAndStop(7);//tells
flash to change frame when the right key is pressed
}
if(Key.isDown(Key.LEFT)){
this._x-=speed;
this.gotoAndStop("8");//tells
flash to change frame when the left key is pressed
}
}
onClipEvent(enterFrame){
if(this._x>550){//assuming
your stage is 550 width
this._x=550;
}
if(this._x<0){
this._x=0;
}
if(this._y>400){//assuming
your stage is 400 height
this._y=400;
}
if(this._y<0){
this._y=0;
}
}This
code allows the player to be moved with the arrow keys, and also stops
the character from moving at the edges of the screen. If you're stage's
size is not 550 x 400, change the numbers 550 and 400 in the code.
That's all for the character for now! On to the other stuff...
Next,
I'll explain score (coins).
If you want any kind of score in
your game, you'll need to follow these instructions.
First, make a
movie clip for your coin. There are no limitations to this movie clip,
so have fun with it and make it look cool. Next, put the following code
on the frame of the game you are playing on:
score=0;Next,
bring the coin movie clip to the stage and put as many of them as you
like. Then, add the following code to each of them:
onClipEvent (load) {
this.swapDepths(_root.getNextHighestDepth());
}
onClipEvent
(enterFrame) {
if (_root.player.hitTest(this)) {
_root.score++;
this.removeMovieClip();
}
}
Now
put a dynamic text box with the variable "score" without the quotation
marks somewhere on the stage. That's all for coins, but theres more
coming!
Every good game has a dynamic camera, also called a
v-cam, right? Right.
First, make a rectangle the size of your
stage (it doesn't matter if it's a little bigger, but it will make a
difference if it's too small). Convert the rectangle to a movie clip and
set the alpha to 0. Also, give it the instance name "vcam" without the
quotation marks. Now put the following code on the first frame
INSIDE
THE VCAM MOVIE CLIP! parentColor.setTransform(camColor.getTransform());
function
camControl() {
parentColor.setTransform(camColor.getTransform());
var
scaleX = sX/this._width;
var scaleY = sY/this._height;
_parent._x
= cX-(this._x*scaleX);
_parent._y = cY-(this._y*scaleY);
_parent._xscale
= 100*scaleX;
_parent._yscale = 100*scaleY;
}
function
resetStage() {
var resetTrans = {ra:100, rb:0, ga:100, gb:0, ba:100,
bb:0, aa:100, ab:0};
parentColor.setTransform(resetTrans);
_parent._xscale
= 100;
_parent._yscale = 100;
_parent._x = 0;
_parent._y = 0;
}
//
make frame invisible
this._visible = false;
// Capture stage
parameters
var oldMode = Stage.scaleMode;
Stage.scaleMode =
"exactFit";
var cX = Stage.width/2;
var cY = Stage.height/2;
var
sX = Stage.width;
var sY = Stage.height;
Stage.scaleMode =
oldMode;
// create color instances for color
// transforms (if
any).
var camColor = new Color(this);
var parentColor = new
Color(_parent);
// Make the stage move so that the
// v-cam is
centered on the
// viewport every frame
this.onEnterFrame =
camControl;
// Make an explicit call to the camControl
// function
to make sure it also runs on the
// first frame.
camControl();
//
If the v-cam is ever removed (unloaded)
// the stage, return the
stage to the default
// settings.
this.onUnload = resetStage;Now,
go back to the main stage and add the following script to the vcam
movie clip:
onClipEvent (enterFrame) {
_y
+= (_root.player._y-_y)/4;
_x += (_root.player._x-_x)/4;
}And
that's how you make the dynamic camera!
I'm sorry to say this,
but that's all I have so far in my RPG, so that's all I can put on this
tutorial. When I get farther along, I'll update this tutorial and add
whatever I did that was new. Thanks for reading! If this helped you, please press the "Thanks" button.
Your forum
admin,
Big Boo