Be a Supporter!

Smoother movement on HP bar

  • 365 Views
  • 10 Replies
New Topic Respond to this Topic
jaksmillie
jaksmillie
  • Member since: Apr. 15, 2008
  • Offline.
Forum Stats
Member
Level 10
Programmer
Smoother movement on HP bar Sep. 30th, 2012 @ 09:04 PM Reply

Hey guys hows it going, so i have this script.

function healthbarscale(e:Event):void
{
	healthbarmc.healthbar.scaleX = healthCurrent/healthTotal;
}

There is more to this code of course, but i was just pasting the essential bit. I am wondering how do i make it so that the health bar has smooth movement when it is being decreased. Not choppy. I looked into it for about an hour, but couldn't figure it out.


BBS Signature
MSGhero
MSGhero
  • Member since: Dec. 15, 2010
  • Offline.
Forum Stats
Supporter
Level 16
Game Developer
Response to Smoother movement on HP bar Sep. 30th, 2012 @ 09:46 PM Reply

There is more to this code of course, but i was just pasting the essential bit. I am wondering how do i make it so that the health bar has smooth movement when it is being decreased. Not choppy. I looked into it for about an hour, but couldn't figure it out.

Look up TweenLite. It's baller at making things smooth (on phone, can't link)

jaksmillie
jaksmillie
  • Member since: Apr. 15, 2008
  • Offline.
Forum Stats
Member
Level 10
Programmer
Response to Smoother movement on HP bar Sep. 30th, 2012 @ 09:58 PM Reply

At 9/30/12 09:46 PM, MSGhero wrote:
There is more to this code of course, but i was just pasting the essential bit. I am wondering how do i make it so that the health bar has smooth movement when it is being decreased. Not choppy. I looked into it for about an hour, but couldn't figure it out.
Look up TweenLite. It's baller at making things smooth (on phone, can't link)

With all due respect, I'd like to learn how to do this in AS3, and not using something else like this tweenlite instrument.


BBS Signature
Eiznek
Eiznek
  • Member since: Aug. 10, 2012
  • Offline.
Forum Stats
Member
Level 01
Programmer
Response to Smoother movement on HP bar Sep. 30th, 2012 @ 10:15 PM Reply

Can't really give you the exact code since I've not touched as for years noe.

What I would do is call another method that would be a for loop that would increment it by a percentage, delay then increment until it reaches the final given value.

At 9/30/12 09:58 PM, jaksmillie wrote:
At 9/30/12 09:46 PM, MSGhero wrote:
There is more to this code of course, but i was just pasting the essential bit. I am wondering how do i make it so that the health bar has smooth movement when it is being decreased. Not choppy. I looked into it for about an hour, but couldn't figure it out.
Look up TweenLite. It's baller at making things smooth (on phone, can't link)
With all due respect, I'd like to learn how to do this in AS3, and not using something else like this tweenlite instrument.
MSGhero
MSGhero
  • Member since: Dec. 15, 2010
  • Offline.
Forum Stats
Supporter
Level 16
Game Developer
Response to Smoother movement on HP bar Sep. 30th, 2012 @ 10:15 PM Reply

At 9/30/12 09:58 PM, jaksmillie wrote: With all due respect, I'd like to learn how to do this in AS3, and not using something else like this tweenlite instrument.

Well, TweenLite is AS3. It's also the best possible tweening platform you can get (until they release an update :P) that even Adobe uses it.

But anyway, the general form for time-based stuff is
(final - initial) / time = rate

You know final and initial, you know time, solve for rate. An example with positions and velocity would be

rate = (400 - x) / 5;  // I want it to move from x to 400 in five seconds
------------------
//each frame
x += rate;

But seriously, use TweenLite.

egg82
egg82
  • Member since: Jun. 24, 2006
  • Online!
Forum Stats
Member
Level 05
Game Developer
Response to Smoother movement on HP bar Sep. 30th, 2012 @ 10:17 PM Reply

At 9/30/12 09:58 PM, jaksmillie wrote: With all due respect, I'd like to learn how to do this in AS3, and not using something else like this tweenlite instrument.

TweenLite is a small framework for tweening things easily. It uses ActionScript 3 because it is made in ActionScript 3 (you can view the source quite easily, it's open-source as well)

don't try to re-create TweenLite or any framework/API/library because at that point you're just re-inventing the wheel and slowing yourself down and pulling your hair out over something that takes a few seconds to download.

Are you going to build your own FlashDevelop or Linux distro just to make games? I wouldn't.


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

BBS Signature
jaksmillie
jaksmillie
  • Member since: Apr. 15, 2008
  • Offline.
Forum Stats
Member
Level 10
Programmer
Response to Smoother movement on HP bar Sep. 30th, 2012 @ 10:34 PM Reply

Alright I guess i'll look into tweenLite, but the reason I don't really want to use it is because I want everything I do in AS to be me, and not some other program.


BBS Signature
egg82
egg82
  • Member since: Jun. 24, 2006
  • Online!
Forum Stats
Member
Level 05
Game Developer
Response to Smoother movement on HP bar Sep. 30th, 2012 @ 11:06 PM Reply

At 9/30/12 10:34 PM, jaksmillie wrote: Alright I guess i'll look into tweenLite, but the reason I don't really want to use it is because I want everything I do in AS to be me, and not some other program.

Might as well start from the basics and create your own Linux kernel from scratch, then. Then you'll need to build your own IDE using your own programming language.

You see my point?


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

BBS Signature
64base
64base
  • Member since: Apr. 18, 2012
  • Offline.
Forum Stats
Member
Level 02
Programmer
Response to Smoother movement on HP bar Oct. 1st, 2012 @ 12:07 AM Reply

At 9/30/12 11:06 PM, egg82 wrote:
At 9/30/12 10:34 PM, jaksmillie wrote: Alright I guess i'll look into tweenLite, but the reason I don't really want to use it is because I want everything I do in AS to be me, and not some other program.
Might as well start from the basics and create your own Linux kernel from scratch, then. Then you'll need to build your own IDE using your own programming language.

You see my point?

Wow you actually explained my stubbornness quite well. I have a Java IDE from a few years ago but then I realised if I used other libraries or frameworks I'd be done in half the time. The only reason I don't like using frameworks or libraries is the fact you can't debug errors exactly to the reference and WHY exceptions are being thrown and the fact you have to learn how to use somebody else's work which makes me go "ughhh". Heck I've even made an intermediate physics engine because I didn't feel the need to learn a way to integrate box2d into my game.


.

PSvils
PSvils
  • Member since: Feb. 3, 2010
  • Offline.
Forum Stats
Member
Level 01
Game Developer
Response to Smoother movement on HP bar Oct. 1st, 2012 @ 04:33 PM Reply

I'll go ahead and also suggest the hidden master of all time, Actuate...

egg82
egg82
  • Member since: Jun. 24, 2006
  • Online!
Forum Stats
Member
Level 05
Game Developer
Response to Smoother movement on HP bar Oct. 1st, 2012 @ 04:36 PM Reply

At 10/1/12 04:33 PM, PSvils wrote: I'll go ahead and also suggest the hidden master of all time, Actuate...

looks impressive, but i'll have to take a look at how to use it. TweenLite so far is even faster than I really want it.

Says the guy who uses uints because they're faster than ints...

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

BBS Signature