Hi people,
I have a fairly simple problem confronting me. I want to implement delta-time into my very simple program. Basically, I want to gauge the time it takes in seconds for one frame to be processed, and multiply the movement speed of my circle by that number each frame.
The code I have is very simple too. I flogged some of it from a post I searched earlier. The problem I seem to be coming up against is that the time.move variable seems to reset to 0 occasionally, stuffing up the circle moving across screen. Also, it doesn't exactly seem to be frame-rate independent.
I understand the basic principle of delta-time, and how to use it, but for the life of me I cannot implement it, or find an example with enough documentation to help my fairly limited coding mind.
The end result I am using this for is a timer. Basically, I want to say "If dude hits this thing, increment this number in seconds till it reaches this ceiling, then reset it". I imagine that would be fairly simple to do, I just need delta-time to work!
So, without further ado, here is my amazingly manly code. Also, if you are willing to help, please explain what you are doing, because I would love to be able to help others when my turn comes to do so!
SYNC on
SYNC RATE 60
type time_num
new as float
old as float
move as float
base as float
endtype
time as time_num
time.base=timer()
move as float
do
cls
time.new = (timer() - time.base) / 1000.0
time.move = (time.new - time.old)
time.old = time.new
print time.old
print time.new
print time.move
print "Move * move timer: " + str$(move * time.move)
inc move, 10.0
circle move * time.move , 100, 50
sync
loop
Thanks in advance for your help guys!
Regards,
Greenlig
Your signature has been erased by a mod as it is far too big.