Using schedule to scale a sprite.
by J.T. Ooley · in Torque Game Builder · 09/21/2010 (5:45 am) · 5 replies
The energy meter is working perfectly. Right now, though, the meter is very jumpy. I know I can fix this with a schedule I'm just not quite sure on the execution. Any ideas?
I should mention too that this function is called on a timer.
I should mention too that this function is called on a timer.
function CheckEnergySource1()
{
EnergySource1.setWidth( $Player::EnergySource1 / $Player::EnergySource1Max * EnergySource1.MaxWidth );
EnergySource1.setPositionX( EnergySource1.leftX + EnergySource1.getWidth() / 2 );
EnergySource1.schedule( 100 , 0 , CheckEnergySource1 );
}
#2
But yea, the bar is filling but it's jumping to each increment. I'm trying to get a smoother transition.
09/21/2010 (6:41 am)
I'm trying to keep everything organized. The onTimer event is in a .cs file associated to the weapon that's being fired. The script I posted is in a .cs file for updating the GUI. I'm hoping it'll be more manageable this way when I start adding weapon upgrades and such.But yea, the bar is filling but it's jumping to each increment. I'm trying to get a smoother transition.
#3
Basically, short difference in width every 100 ms is 'smoother' than that big difference every 200 ms...:)
09/21/2010 (6:52 am)
It's 'jumping' because the difference between the widths is high and is noticeable to the human eye. Shorten the timer interval to I dunno, 200, 100 ms?Basically, short difference in width every 100 ms is 'smoother' than that big difference every 200 ms...:)
#4
The meter is for the weapon's cooldown. If I shortened the timer interval it would replenish the weapons energy quicker than I'm wanting it to. I want to use a shedule so that the sprite is stretched to the next increment over time. So in theory, the meter would be working off of two different timers.
edit:
I fixed it by messing with the ammo and switching a line of code to a different timer. Not exactly how I was wanting it to work, but it works just as well :P
09/21/2010 (7:14 am)
I know why it's jumping :P The meter is for the weapon's cooldown. If I shortened the timer interval it would replenish the weapons energy quicker than I'm wanting it to. I want to use a shedule so that the sprite is stretched to the next increment over time. So in theory, the meter would be working off of two different timers.
edit:
I fixed it by messing with the ammo and switching a line of code to a different timer. Not exactly how I was wanting it to work, but it works just as well :P
#5
09/24/2010 (6:38 am)
Good to hear.
Torque Owner Aditya Kulkarni
Loon Games
Why the recursive code? It would be easier if you just set the width and position on your onTimer event.