PDA

View Full Version : two timers at time



WiZz
16-02-2004, 09:45 AM
i created a game using simple timer, but then i decided to change it into DXTimer, but in my project is 4 timers. one if hero go tu north, other if hero go to the south..... and i need to run two timers but it dosen't work. with simple timer everything was ok how to run two dxtimers?

Paulius
16-02-2004, 10:51 AM
While TTimer is based on Windows messages, DXTimer (if I remember correctly) uses OnIdle event, making only one of these usable at a time. Using many timer's is not really a good idea anyway, it's much better to make one fast timer and put everything timing related in it's OnTimer event, like:

if Action1Enabled then
begin
inc(Action1Time);
if Action1Time > Action1NeededTime then
begin
DoAction1;
Action1Time:= 0;
end;
end;

if Action2Enabled then
begin
inc(Action2Time);
if Actio2Time > Action2NeededTime then
begin
DoAction2;
Action2Time:= 0;
end;
end;etc.

WiZz
16-02-2004, 11:34 AM
well you see i need 4 timer, i don't know how to change them to one. for example if hero is in [0, 0] and he need to go to [5, 9] xtimer and ytimer will be enabled while hero reaches [5, 5] then xtimer.enabled := false; and only ytimer will be active.

Paulius
16-02-2004, 11:41 AM
Change Action1Enabled to Xcurrent <> Xwanted, etc.