Be a Supporter!

How to make a bar charge over time?

  • 284 Views
  • 9 Replies
New Topic Respond to this Topic
Fatelogic
Fatelogic
  • Member since: May. 3, 2012
  • Offline.
Forum Stats
Member
Level 11
Artist
How to make a bar charge over time? Dec. 17th, 2012 @ 11:17 PM Reply

Hello guys, Fate here. As usual, ready to annoy you, oh wise ones, with questions regarding Flash CS6 and AS3 :D

Tonight, I have a simple (I hope) question:

How do I create a bar (energy bar, mana bar, power bar, whatever bar) that charges over time? Let me explain a little better what I need:

I need to create a bar that fills itself over time from 0% to, let's say, 25% in 10 seconds and, when it reaches that 25%, it stops filling any further.

The whole concept and application is way more complex than that, but I somewhat sorted out the other parts I need for the whole script to work, so I'm listening to your feedback, folks :D

Thanks in advance for your help. In case I end up trying your suggestions and finish getting into some kind of trouble, I'll reply and will go into further detail about the particular issue, but let's hope it's not necessary.

Thanks again!

Fate out!

MintPaw
MintPaw
  • Member since: Jun. 11, 2006
  • Offline.
Forum Stats
Member
Level 10
Programmer
Response to How to make a bar charge over time? Dec. 17th, 2012 @ 11:46 PM Reply

I'd suggest you take a look at the scaleX property, Number variables, and the Timer class.


If ya have something to say, PM me. I have a lot of time to spare.
Also never PM egg82.

BBS Signature
Fatelogic
Fatelogic
  • Member since: May. 3, 2012
  • Offline.
Forum Stats
Member
Level 11
Artist
Response to How to make a bar charge over time? Dec. 17th, 2012 @ 11:57 PM Reply

At 12/17/12 11:46 PM, MintPaw wrote: I'd suggest you take a look at the scaleX property, Number variables, and the Timer class.

I know the first two are involved AND I "somewhat" know how to deal with them. It's the Timer class that's new to me and... well, the tutorials on how to use it often reffer to using it on a numeral clock, so it's full of scripting that transcribes the timer value to visible numbers and such (aka: additional baggage that's not needed for this) aaaaaaaaand I get a little lost trying to fish out what's useful and what's not. That's why I posted the question here, so maybe someone knows a more direct way to do what I intended and, therefore, saving me some precious ours of my mental stability xD

I'll have to go back to those tutorials if nothing works though, so thanks for the feedback anyway ^^

MSGhero
MSGhero
  • Member since: Dec. 15, 2010
  • Offline.
Forum Stats
Supporter
Level 16
Game Developer
Response to How to make a bar charge over time? Dec. 18th, 2012 @ 12:20 AM Reply

Republic of code is always very helpful for the basics, plus the docs.

Fatelogic
Fatelogic
  • Member since: May. 3, 2012
  • Offline.
Forum Stats
Member
Level 11
Artist
Response to How to make a bar charge over time? Dec. 18th, 2012 @ 12:22 AM Reply

At 12/18/12 12:20 AM, MSGhero wrote: Republic of code is always very helpful for the basics, plus the docs.

Yeah, I check Republic of code everytime I'm messed up with something, but this one slipped my radar. I'll check it out and see if it can get the job done, thanks.

egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Member
Level 05
Game Developer
Response to How to make a bar charge over time? Dec. 18th, 2012 @ 09:14 AM Reply

The way I figured out most of AS3's classes is by reading the official documentation and playing with the values and functions.


Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P

BBS Signature
pirateplatypus
pirateplatypus
  • Member since: Sep. 27, 2011
  • Offline.
Forum Stats
Member
Level 15
Programmer
Response to How to make a bar charge over time? Dec. 18th, 2012 @ 01:13 PM Reply

At 12/18/12 09:14 AM, egg82 wrote: The way I figured out most of AS3's classes is by reading the official documentation and playing with the values and functions.

That's been the most useful way for me too. As useful as game making tutorials can be, I've understood things much more when I figure it out from the Live Docs.


"If loving Python is crazy then I don't want to be sane." -Diki

nitokov
nitokov
  • Member since: May. 8, 2012
  • Offline.
Forum Stats
Member
Level 05
Programmer
Response to How to make a bar charge over time? Dec. 18th, 2012 @ 07:17 PM Reply

dont use too much timers its hard on preformance.
Create a movie clip with 100 frames and draw bar, then make mask layer and create tween so that frame 1 will represent 0% and frame 100 100%. Also it can be 50 frames just change last number in this code according to it, and run it on change or on enter frame
if(current_health > 0)
{
gotoAndStop(Math.ceil(current_health / total_health * 100));
} else {
stop();
}

hope it will do the trick for you ;)


RangeError: Error #1125: The index 4 is out of range 4.

egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Member
Level 05
Game Developer
Response to How to make a bar charge over time? Dec. 18th, 2012 @ 07:42 PM Reply

At 12/18/12 07:17 PM, nitokov wrote: dont use too much timers its hard on preformance.

you tell him not to create too many timers because of performance reasons, and then tell him to create a MovieClip, a mask, and a tween?

also, don't do this. You can easily create a functional health bar in code, why in the world would you want to drag MovieClips and frames into the picture? All that would do is make it very inflexible and hard to work with.


Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P

BBS Signature
Fatelogic
Fatelogic
  • Member since: May. 3, 2012
  • Offline.
Forum Stats
Member
Level 11
Artist
Response to How to make a bar charge over time? Dec. 18th, 2012 @ 08:53 PM Reply

Thanks for the help guys, I already worked my way through this problem ^^

However, I found a new problem xD So I'll post a new question in the forum. See ya there :P