현재 x를 작은 단계로 위로 움직이는 TCard (TGraphicControl)가 있습니다. 그러나 나는 그것을 뒤로 움직이는 방법을 이해할 수 없다.완료되면 이미지를 다시 가져 오는 방법
내가이 내부
TCardMover.Slide(card,point(card.Left,card.Top -10),CARD_SLIDE_TIME,Animation);
로 시작
procedure TGameData.AnimateAttack(slot: Integer;card: TCard); //add value as integer ,
var
i : integer;
begin
i:=0;
if slot = 1 then
begin
//TCardMover.Slide(card,point(card.Left,card.Top -10),CARD_SLIDE_TIME,Animation,nil);
TCardMover.Slide(Card,point(Card.Left,Card.Top -10),CARD_SLIDE_TIME,Animation,TerminateCall);
end;
if slot = 2 then
begin
TCardMover.Slide(card,point(card.Left,card.Top -10),CARD_SLIDE_TIME,Animation,TerminateCall); // DMc Just to test card movement
end;
if slot = 3 then
begin
TCardMover.Slide(card,point(card.Left,card.Top -10),CARD_SLIDE_TIME,Animation,TerminateCall); // DMc Just to test card movement
end;
end;
을 {이 공격 amimation을 줄 것이다} 내가 tCardMover을 실행하면 다음 내가
procedure TGameData.attack;
begin
animateAttack(1,fgame.Slot1);
end;
과 같이 호출 animateattack에서 이와 같이 바로 뒤에서 .slide.
TCardMover.Slide(card,point(card.Left,card.Top -10),CARD_SLIDE_TIME,Animation);
TCardMover.Slide(card,point(card.Left,card.Top +10),CARD_SLIDE_TIME,Animation);
두 가지 모두 시도해 봅니다. 움직이기 때문에 별도의 스레드라고 생각합니까? 어떻게하면 -10을 움직일 수 있고 카드가 끝나면 10을 움직일 수 있습니까?
여기에 TCardMover가 있습니다.
{ TCardMover }
function TCardMover.Arrived: boolean;
begin
Result := (FPosNow.X = FPosDest.X) and (FPosNow.Y = FPosDest.Y);
end;
procedure TCardMover.CalculateNextStop;
var
Elapsed : integer;
begin
while FTickNext < GetTickCount do // When is next re-draw due?
FTicknext := FTickNext + CARD_MOVE_INTERVAL;
if FTickNext >= FTickEnd then // Are we there yet Dad?
begin // If the journey has taken long enough, move
FTickNext := FTickEnd; // to our destination without further delay,
FPosNow := FPosDest; // then bail.
end
else
begin
// If we get here we are still en route so calculate where to re-draw.
Elapsed := GetTickCount - FTickStart; // How much time will journey have taken at next re-draw?
FPosNow.X := FPosStart.X + round((Elapsed/FTickJourney)*FJourney.X); // Where will card be at next re-draw?
FPosNow.Y := FPosStart.Y + round((Elapsed/FTickJourney)*FJourney.Y);
end;
end;
procedure TCardMover.Execute;
begin
while not terminated and not Arrived do
begin
CalculateNextStop;
WaitTillDue;
Synchronize(NotifyHost);
end;
end;
class procedure TCardMover.Slide(aCard: TCard; aDestination: TPoint; aJourneyTime: cardinal; DrawProc : TNotifyEvent);
begin
with TCardMover.Create(START_IMMEDIATELY) do
begin
FTickStart := GetTickCount;
FTickNext := FTickStart;
FTickEnd := FTickStart + aJourneyTime;
FPosStart := Point(aCard.Left,aCard.Top);
FCard := aCard;
FPosDest := aDestination;
FTickJourney := aJourneyTime;
FreeOnTerminate := TRUE;
FOnMove := DrawProc;
FJourney.X := FPosDest.X - FPosStart.X;
FJourney.Y := FPosDest.Y - FPosStart.Y;
end;
end;
procedure TCardMover.NotifyHost;
begin
if assigned(FOnMove) then
FOnMove(Self);
end;
procedure TCardMover.WaitTillDue;
var
TicksNow : cardinal;
begin
TicksNow := GetTickCount;
if TicksNow < FTickNext then
SleepEx(FTickNext-TicksNow,DO_NOT_QUIT_EARLY);
end;
스레드는 대기 부분과 sychronized 이동 부분이있다. 당신은 양식에 간단한 TTimer로 이것을 처리 할 수 있습니다. –