469,927 Members | 1,790 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

Health bar percentage rise help needed

Ok, for the game that I am creating at the moment I have a health bar animation that starts off full and empties as time goes on. When the health bar is empty it goes to the gameover screen. This part works fine.

What I would like to happen is when the user runs into a target for the bar to increase by 10%, giving the user more time. The way it is set up at the moment the healthbar movieclip has the instance name "healthbar".

Inside this are 100 frames showing the bar going down (shape tween broken down into keyframes). 1 is the full healthbar, 0 is the empty healthbar.

On the target I have the following code:

//10 is the number of frames I would like to increase the bar by
_root.healthbar += 10;

However the bar just seems to keep going down. I think I need to find out the current frame the bar is at before adding 10 pixels to it but dont know how. Any help, can provide the .Fla if needed.


Sep 18 '07 #1
1 3328
If you're using _root.healthbar += 10 exactly as you have typed that is your problem. "_root.healthbar" represents a MovieClip, so adding the Number 10 to the MovieClip isn't going to do anything.

Try This:
Expand|Select|Wrap|Line Numbers
  1. _root.healthbar.gotoAndPlay(_root.healthbar._currentframe + 10);
The above would be for ActionScript 2 (I'm assuming because of the depreciated _root keyword that's what you're coding in) - if you're using AS3 the equivalent is something like .currentFrame - I think.

Edit: bleh for some reason in the code listing it's putting curre ntframe - with spaces in _currentframe. Make sure that's all one word if you copy and paste it.
Sep 22 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by SK | last post: by
7 posts views Thread by Bruce MacDonald | last post: by
2 posts views Thread by Debbie E | last post: by
1 post views Thread by Bigeloww | last post: by
4 posts views Thread by Maddy | last post: by
4 posts views Thread by Klauer | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.