Flash Game Making Tutorial - Part 3

hero.png
C64 H.E.R.O - One of my favorite retro games

Hey there ninjadoodles and welcome back! Last week we left our poor Ninja Square all alone in a single gray room with nothing to do. Today we’re gonna teach the little dude how to face in different directions! WHOA, exiting you say?! Well not really, BUT, do you really want to keep staring at a faceless square in the middle of your screen, wondering if a pair of eyes are hidden somewhere beneath that black disguise staring at you!?

Today’s lesson is quite straight forward, do open up your flash movie from last week and let’s go.

Double click on your Ninja MovieClip and insert 2 new layers with 5 empty keyframes on each. Call one layer actions and place a stop(); action on each frame.

wizard-of-wor.png
C64 Wizard of Wor - spooky dungeons and sfx

Name the second layer labels and call the 5 keyframes “left”, “right”, “up”, “down”, and “idle”. It is completely up to you whether you place a still graphic or an animated MovieClip (such as a walkcycle) on the corresponding keyframes.

When you press a certain key, we want the Ninja MovieClip to change to the corresponding keyframe within itself. If no key is being pressed, the Ninja should go to the “idle” keyframe.

Now the only thing left to do, is to add the code, so make the following additions/changes to your onEnterFrame function …

onEnterFrame = function() {
	if ((Key.isDown(key.LEFT)) and (ninja._x-5 > minX)) {
		ninja._x -= speed;
		ninja.gotoAndStop("left");
	} else if ((Key.isDown(key.RIGHT)) and (ninja._x+5 < maxX)) {
		ninja._x += speed;
		ninja.gotoAndStop("right");
	} else if ((Key.isDown(key.UP)) and (ninja._y-5 > minY)) {
		ninja._y -= speed;
		ninja.gotoAndStop("up");
	} else if ((Key.isDown(key.DOWN)) and (ninja._y+5 < maxY)) {
		ninja._y += speed;
		ninja.gotoAndStop("down");
	} else {
		ninja.gotoAndStop("idle");
	}
}

As you see, the code is pretty self-explanatory. Play around with you graphics and maybe add a small animation to each of your directions before next week. :)

See ya!

^ One Comment...

  1. jamjar3000

    i was just wonderin… wat flash do u need, where do u get it and how much does it cost???? if u have any idea of the answer to these post it as a comment on this youtube channel *http://www.youtube.com/user/jamjar3000*
    ( also if u know the answer to these questions for makin movies plz also send a comment) TY :)

) Your Reply...