Computer Science Canada

Slowing Down a Program

Author:  josh [ Thu Jul 15, 2004 8:59 am ]
Post subject:  Slowing Down a Program

Here is the problem:

I am nearing the end of a two week course in which we learn Java by making our own version of the game asteroids. The thing is we are working n shitbox PC's (old, white Dell Pentium 3's) and when I take my program home it moves way to fast i.e. the asteroids zoom all over the screen, when I hit the space bar only for a second it fires 20 torpedoes instead of 1).

I could go through all my code and play around with the timers and variables (willpost the game and souurce code when I am done, probobly monday) but I was wondering if their was an easier way to do it by just using a command that slows down your system.


Author:  rizzix [ Thu Jul 15, 2004 3:16 pm ]
Post subject: 

lol hehe. well a timer should always work.. right. i mean do different computers display the time at a different rates?

but wat u need to do is ensure the the motion of the object is related to time. that way its always consistant. right now the motions of the objects is simply a pixel by pixel incermentation right.? i'm sure it is and time is really not a dependent factor for the motion.. so of course its different on different machines. the motion is dependent on processing power rather then time.

now the problem with using time soley as the dependent factor is that the movement it not smooth. it tends to jerk etc (because of that "period" between seconds, u'd need a timer in nanoseconds or less for smoother animation).. so if u can instead hybrid the two in someway that would give u the best of both worlds.

Author:  josh [ Thu Jul 15, 2004 3:40 pm ]
Post subject: 

well, all the timers in my program are actualyl count down each time the screen is repainted. so I am not sure how I would do that. It is not really time that is being used, and the reason it is so much faster is thta obviously my PC can repaint the screen much faster than the PC I am building the game on.

Author:  da_foz [ Fri Jul 16, 2004 4:42 pm ]
Post subject: 

So what the other poster is saying is if you use the System.time() (or whatever the call is) then you have a somewhat steady counter that is not dependent on raw computer power. ie,. when System.time() increments then move the objects. However, Java is really bad dealing with time, it is very inaccurate. So the other poster suggested a hybrid solution. Something like have the counter as you have it now, and add System.time() to it. You will have to do some scaling, such all I think the System.time might return a number in milliseconds so the number you have will be big. Take the big nubmer and divid by 1000 or something and round the answer. That way sometimes things will move, and sometimes they will stay in the same spot.

Did that make any sense to you?

Author:  josh [ Mon Jul 19, 2004 10:27 am ]
Post subject: 

not really. Soon I will post the source to my program, that might help if u can show me where. I jsut need to clean it up a bit first.

I also have never heard of System.time(). the course I took was kinda linear, they tol us what code to right sort of thing so theri are lots of functions I still do not know.

Author:  CaptainEvil [ Mon Jul 19, 2004 9:52 pm ]
Post subject: 

Hey Cap here,

I was in RysticLight's Java class, and, as he said, yes it was fairly linear, as our instructor merely told us what to write, eventually we caught on and learned a few things, hehe, but he did not go into detail about certain functions, calls, timers etc. He merely gave us the jist of the program.
Anyway, I myself have a problem. A problem finding Sprites. If anyone could tell me the whereabouts of websites that carry them or if you have some yourself that'd be great thanks!


-"If you're gonna be a fool, might as well be a dancing fool."

Author:  Delta [ Sat Jul 24, 2004 7:54 am ]
Post subject: 

CAP STOP ASKING FOR SPRITES IN EVERY POST!!!! Mad jeez man 3/4 of your posts (haven't seen the fourth... prolly in there too) put it in your signature then!

Look into Asian's or Catalyst's FSP tutorial in the turing section and see if you could do something like that... I'm sure it's possible... so that's prolly your best bet... or look into sleep delaying for java (sleep, catch or things like that)... Have a nice day...