Cool Sprint/Energy Bar For Games [Flash][Actionscript]

Started by: Minty | Replies: 18 | Views: 4,945

Minty
2

Posts: 43
Joined: Aug 2005
Rep: 10

View Profile
Jul 16, 2006 5:17 PM #11941
This is just a quick sprint/energy bar that you can use for games. Note: I am using Flash MX 2004, and I have not tested this on any other versions.

Ok so start of with creating a circle, doesn't matter what colour or anything. This will be your character. Call it man, and make sure it's a movie clip.

Now we are going to create the energy bar. Go back to the main stage and create a retangle, any colour you want. Select it and press f8, call it bar and make sure it's a movie clip. Go back to the main stage, select the bar, and press ctrl+f3 to open up the properties inspector. Do the following:


W:100.0 X:19.0
H:19.0 Y:19.0


Then set the instances name to 'bar' WITHOUT the quotations. Now select the man, and press f9 to open the actions panel. Copy and paste these actions in the action panel:


onClipEvent (load) {
moveSpeed = 5;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.SHIFT) && _root.bar._width>=3) {
moveSpeed += 0.5;
} else {
moveSpeed -= 0.5;
}
if (Key.isDown(Key.LEFT)) {
this._x -= moveSpeed;
}
if (Key.isDown(Key.RIGHT)) {
this._x += moveSpeed;
}
if (Key.isDown(Key.UP)) {
this._y -= moveSpeed;
}
if (Key.isDown(Key.DOWN)) {
this._y += moveSpeed;
}
if (moveSpeed >10){
moveSpeed = 10;
}
if (moveSpeed <5){
moveSpeed = 5;
}
}


Explanation: This is fairly simple. It sets the movespeed of the character to 5. Then says that if the key shift it down, AND the bar width is bigger than 3, then increase the movespeed by 0.5, until it reaches 10, and thats its max speed. Then if the shift key is not down, decrease the movespeed by 0.5, and minimum movespeed is 5. The rest is just the basic movements for your character.

Now select your bar movie clip, and press f9, and put these actions inside:


onClipEvent (enterFrame) {
if (Key.isDown(Key.SHIFT)) {
_width -= 3;
} else {
_width += 1;
}
if (_root.bar._width>=100) {
_width = 100;
}
}


Explanation: All this says is that if the shift key is down, make the bar width decrease by 3, or if the shift key is not down, increase the bar width by 1. Then the second part basically says if the bar width is bigger than 100, set the width to 100. This insures that the bar width will not go past it original width.

There you go, test your movie, and it you will be able to press shift, and your character will move twice as fast, and the sprint bar will decrease.

There is one more thing you can add, it's a cool number that will follow the enery bar, showing the percentage of energy left.

Select the text tool, open up the properties inspector, and select a dynamic textbox. Create a dynamic textbox, and make it big enough so that it can fit 3 numbers in it. Now select the textbox, and open up its properties inspectors, and make the var 'sprint' without the quotations. Select the textbox and press f8, and make it a movie clip called Sprint Text. Go back to the main stage, select the textbox Movie clip, and open it's properties inspector. Set these properties to it:


W: 35.0 X: 120.0
H: 24.1 Y: 16.8


Now select the textbox, and press f9 to open up its actions. Copy and paste these actions inside:


onClipEvent (load) {
sprint = 100;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.SHIFT)) {
sprint -= 3;
_x -= 3;
} else {
sprint += 1;
_x += 1;
}
if (_x<22>=120) {
_x = 120;
}
if (sprint <0>= 100) {
sprint = 100;
}
}


Explanation: This all just is repeat from all the other scripts. Pretty self-explanatory.

There, test your movie, you should now have a percentage that shows how much energy you have left. You can find the SWF example here: http://media.putfile.com/Example-9

If there are any errors please tell me so I can fix them.

~Minty
Silent_ninja_assassin
2

Posts: 31
Joined: Apr 2006
Rep: 10

View Profile
Jul 16, 2006 5:29 PM #11945
´wow thanks great tut
LethalBunny

Posts: 0
Joined: Oct 2025
Jul 18, 2006 12:53 AM #12051
lol

Minty has been hoarding that tut for some time.
Paperclip

Posts: 840
Joined: Nov 2004
Rep: 500

View Profile
Jul 19, 2006 1:35 AM #12101
Great! I was looking for something like this... great job Minty.
StickShaz

Posts: 0
Joined: Oct 2025
Jul 20, 2006 6:04 PM #12138
thanks m8 helped me out
Minty
2

Posts: 43
Joined: Aug 2005
Rep: 10

View Profile
Jul 23, 2006 6:00 PM #12240
Minor Update- Just a small update, actually its barely noticable lol. The character now speeds up to his maxspeed, instead of immedietely going faster. And he also decrease his speed, instead of immediately changing back. Adds a touch of realism.
Daro

Posts: 0
Joined: Oct 2025
Jul 23, 2006 6:20 PM #12242
very very very cool :D
Steyene

Posts: 2,060
Joined: Apr 2006
Rep: 10

View Profile
Jul 25, 2006 9:17 AM #12367
great now i just need to find a time and place where i can use this great bit of info...
Scarecrow
2

Posts: 9,168
Joined: Oct 2005
Rep: 10

View Profile
Aug 25, 2006 11:31 AM #13964
This is a very good idea. Good job, if I ever make an rpg, I'm guaranteed to use this.
LN3uq
2

Posts: 2,457
Joined: Dec 2004
Rep: 35

View Profile
Aug 25, 2006 3:54 PM #13970
I love you minty.

I mean, I love the tut.

>_>
Myself

Posts: 7,010
Joined: Apr 2006
Rep: 10

View Profile
Sep 16, 2006 9:29 AM #15438
Minty = Better than Tic-Tacs.

Nice tut.
Deathbat.
2

Posts: 1,359
Joined: Sep 2006
Rep: 10

View Profile
Oct 4, 2006 3:41 PM #16221
dude thats an ace tut

yay this is my 100th post.

minty u rule!
dilland
2

Posts: 50
Joined: Nov 2006
Rep: 10

View Profile
Nov 24, 2007 2:33 AM #68991
lol i will use this. thanks minty, for everything >_<
Saline
2

Posts: 653
Joined: Dec 2006
Rep: 10

View Profile
Dec 3, 2007 11:18 PM #70387
I think I might've entered something wrong in the code, but when you just hold down shift the bar goes down.
Beta
2

Posts: 776
Joined: Feb 2007
Rep: 10

View Profile
Dec 4, 2007 11:38 PM #70464
One month bump? lolwut?

Or 2 weeks, whatever.

Wait, dilland did a 1 YEAR bump. Oshi.