Drawing a rectangle in a certain amount of time
BlitzPlus Forums/BlitzPlus Beginners Area/Drawing a rectangle in a certain amount of time
| ||
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 |
| ||
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. |
| ||
Thank you! Here is the finished code for anyone who needs it: |
| ||
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. |
| ||
For starters, rectlength should not include the startx term at the end. |
| ||
^^ Thank you. It works flawlessly now. |