Drawing a rectangle in a certain amount of time

BlitzPlus Forums/BlitzPlus Beginners Area/Drawing a rectangle in a certain amount of time

Dale Nation(Posted 2013) [#1]
Hello,

I am completely stumped. Does anybody know how to draw a rectangle from point(x,y) to point(nx,ny) in a specified amount of time? Could somebody make that function for me? In my game I have a timer, and I want a progress bar. When the timer starts, the rectangle is very small, but by the time the timer is finished, the rect is stretched in length all the way to the end. I tried some different math, but nothing worked!



Regards


TomToad(Posted 2013) [#2]
currentx=(endx-startx)*(float(timepassed)/float(lengthoftime))+startx

There are other ways of calculating the length. The biggest mistake is forgetting to use floats in the division, causing the stretching to not be as smooth.


Dale Nation(Posted 2013) [#3]
Thank you!

Here is the finished code for anyone who needs it:




Dale Nation(Posted 2013) [#4]
Oooh. However, the code above does *not* work is the startx coordinate is not at zero. Try it at startx=250 and endx= 300.

Edit: I edited the code with it working correctly now.


Who was John Galt?(Posted 2013) [#5]
For starters, rectlength should not include the startx term at the end.


Dale Nation(Posted 2013) [#6]
^^

Thank you. It works flawlessly now.