1
我使用一個線程和一個簡單的遊戲循環的同步過程。 在我的電腦上,Windows 7,它的魅力,但當我在我的Android設備上運行它,當我點擊播放和線程啓動後,屏幕變黑或有時變暗,有時保持正常,但屏幕上可見所有對象延伸或無法正確渲染;此時線程似乎被凍結(來自主窗體的音樂仍然繼續播放)。德爾福XE8 TThread在Android上凍結,但在Windows上工作
這裏是線程本身:
procedure TTheThread.Loop;
begin
MainForm.GameLoop;
end;
procedure TTheThread.Execute;
begin
while NOT Terminated do
begin
Application.ProcessMessages;
TC:= TStopwatch.GetTimeStamp;
//The Following repeats itself every second:
if TC>(TCTime+10000000) then
begin
TCTime:= TStopwatch.GetTimeStamp;
TimeT:= TimeT+1; //Time in seconds
//Increasing game playing speed:
Gravity:= Gravity + 0.0075 * DEF;
PJump:= PJump+IncJump
end;
//...just to have it on screen:
With MainForm do
Label1.Text:= IntToStr(TC);
//This seems to make the loop run smooth and without lagging on my PC:
if TC>(TCLast) then
begin
Synchronize(Loop);
TCLast:= TC;
end;
end;
end;
這是如何開始:
TCTime:= TStopwatch.GetTimeStamp;
TCLast:= TCTime;
GameThread:= TTheThread.Create(True);
GameThread.FreeOnTerminate:= True;
GameThread.Start;
感謝您的信息!我真的很快刪除了'Application.ProcessMessages()'並創建了一個新的同步過程,現在它就像它應該那樣工作,就像在Windows上一樣。 – Vepir