Gajo Istvan wrote:

<snip>
procedure TForm1.Move(x,y,angle: integer; M: TMoving; time: integer);
begin
 if time = GetTickCount then begin
  CalcXY(x,y,angle);   // gets new coordinates
  UpdateM(M);          // updates bitmap coordinates
  Move(x,y,angle,M,GetTickCount+2)  // call itself with new time
 end else
  Move(x,y,angle,M,time)   // call itself with same time
end;

A routine like the above should NOT call itself. That's just horrid. You're just begging for a stack overflow, and you'll get it in a very short amount of time.


At the least you should be using a loop instead of unfettered recursion. But more importantly, your routine above NEVER exits. Even rewriting it with a loop instead of recursion isn't going to change that.

You could use a thread to do your game loop, but it's not really necessary. All you need to do is process messages implicitly at some point in your loop and all will be well. The following pseudo-code for example:

  while not exiting...
    Application.ProcessMessages
    Move game objects
    Update display
    Sleep (or whatever)

In fact to stick with the event-driven paradigm you could use a multimedia timer and put the move and update display in the event handler for the timer.

--
Corey Murtagh
The Electric Monk
"Quidquid latine dictum sit, altum viditur!"

_______________________________________________
Delphi mailing list
[EMAIL PROTECTED]
http://ns3.123.co.nz/mailman/listinfo/delphi

Reply via email to