我正在製作從窗戶窗體的一側移動到另一側的小船的動畫,但是當船隻接觸到窗體的邊緣時,我必須通知用戶屏幕因爲他贏了。任何人有任何想法如何做到這一點? 這是我到目前爲止有:檢查動畫是否在Winform中的屏幕邊緣
private void playerTimer_Tick(object sender, EventArgs e)
{
for (int i = 0; i < 6; i++)
{
if (PlayersActive[i])
{
Players[i].Move(randomNumber.Next(3,10));
//HERE IS WHERE I SHOULD CHECK TO SEE IF A BIKE HAS WON
//If player location is at the edge of the screen
}
}
this.Invalidate();
}
代碼移動船隻:
private void GameForm_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
// Set variables used to store logic to default values.
int playersStillRacing = 0;
for (int i = 0; i < 6; i++)
{
// Check to see if the current player is still racing.
if (playersRacing[i])
{
// Incremement playersStillRacing.
playersStillRacing++;
// Set the playerPictureBox associated with this player to the new location
// the player is located at.
playerPictureBoxes[i].Image = Players[i].Image;
playerPictureBoxes[i].Left = Players[i].X;
playerPictureBoxes[i].Top = Players[i].Y;
g.DrawImage(playerPictureBoxes[i].Image, Players[i].X, Players[i].Y);
}
}
}
它涉及到你的「自行車」的長度,你如何渲染你的「自行車」(直接使用一些控件或只是繪製它) –
要繪製自行車,我使用paint事件,然後使用drawImage,因爲它是一個圖片我從互聯網的圖片調整大小。 – Mirimari
你如何增加Players [i] .X?如果你採用Players [i] .X值和Players [i] .Image的寬度,那麼你將能夠看到圖像是否接觸到結尾。 – MasterXD