Can't find my error in timer code
Blitz3D Forums/Blitz3D Beginners Area/Can't find my error in timer code
| ||
Hello All! Funny how I can easily do complex things but cannot do simple things! So plaes, go ahead and call me an idiot (because i am one hehehe) but please let me know wheremy error is. I am trying to make a simple counter that counts down from 99 seconds to zero using sprites (64X64 pixels). I have 10 sprites, each in JPG format named one, two,.....,zero. My timer reads the current milliseconds and then counts down the 'ones of seconds' in an integer format each second until it reaches ZERO. Once it reaches ZERO seconds it turns agin to 9 seocnds, subtracts 1 from the tens of seconds and proceeds to count down. This works for about 40 or seconds and then the program halts saying that it cannot find the sprite for the ones-of-seconds...which is odd because it found it the last three times around. If anyone can tell me what I did wrong, please let me know so I can stop screaming IDIOT at myself. Here's the code: Graphics3D 640,480 ;create camera so I can see campivot = CreatePivot() cam = CreateCamera(campivot) MoveEntity cam,0,0,-5 ;get feed time from CPU clock for starting point stime=MilliSecs() ;set timer to 99 seconds Global tens=9 Global ones=9 While Not KeyDown(1) ;this hsould make a 10 second timer timeleft=ones-((MilliSecs()-stime)/1000) ;timeleft creates our ones place readout Select timeleft Case 1 clock$="one" Case 2 clock$="two" Case 3 clock$="three" Case 4 clock$="four" Case 5 clock$="five" Case 6 clock$="six" Case 7 clock$="seven" Case 8 clock$="eight" Case 9 clock$="nine" ;if the seonds are zero then lessen tens of seconds, restart the start time, and reset the ones Case 0 clock$="zero" ones=9 tens=tens-1 stime=MilliSecs() End Select ;change tens readout for tens of seconds Select tens Case 1 clock2$="one" Case 2 clock2$="two" Case 3 clock2$="three" Case 4 clock2$="four" Case 5 clock2$="five" Case 6 clock2$="six" Case 7 clock2$="seven" Case 8 clock2$="eight" Case 9 clock2$="nine" Case 0 clock2$="zero" End Select ;stop the program when timer reaches 0-0 If ones + tens=0 Then End ;show the seconds in the upper left FreeEntity sp sp = LoadSprite(clock$+".jpg") SpriteViewMode sp,4 ScaleSprite sp, 0.1,0.1 PositionEntity sp,-3.5,3,0 ;show the tens of seconds in the upper left FreeEntity sp2 sp2 = LoadSprite(clock2$+".jpg") SpriteViewMode sp2,4 ScaleSprite sp2, 0.1,0.1 PositionEntity sp2,-3.7,3,0 RenderWorld:Flip UpdateWorld Wend End |
| ||
You might try not loading the sprites each loop. Load tham all at the begining and scale them, then only position them at the place where their supposed to be each loop. You might have to hide them and show them too. |
| ||
or you could use this: http://www.blitzbasic.com/codearcs/codearcs.php?code=1646 |