Delta time problem

BlitzMax Forums/BlitzMax Programming/Delta time problem

MarkSponge(Posted 2006) [#1]
I have an image moving across the bottom of the screen. When I move press the left cursor the image moves at the correct speed. When I press the right cursor the image take a second longer to travel the width of the screen.

Code Below:

Image type variable:
Field Speed#=640/4

Image type update method:
If KeyDown(KEY_LEFT)
X :- self.Speed*DeltaTime
EndIf
If KeyDown(KEY_RIGHT)
X :+ self.Speed*DeltaTime
EndIf

In the main loop:
DeltaTime = ( MilliSecs()- TimeDelay )*0.001
TimeDelay = MilliSecs()

I don't know what is going on.

Thanks in advance.

Mark


LarsG(Posted 2006) [#2]
I don't know from just looking at that code.
The only thing I would suggest, is to make sure that DeltaTime and the X variable are float values.


MarkSponge(Posted 2006) [#3]
That did it, I had the X variable as an Int.

How embarrassing.


LarsG(Posted 2006) [#4]
it's a common mistake.. I'm sure everybody has done a few of those.. :p


Grey Alien(Posted 2006) [#5]
Yeah I keep making vars that should be floats and puzzling over why the result isn't as expected.