2016-01-16 127 views
0

請大家幫忙!!!!小小的基本復位形狀位置離開屏幕後

我在與小的基本

我想作一個小遊戲,一個不明飛行物必須避免小行星有點問題,和我做了一個小行星和動畫,然後我想讓其y位置返回到0文便通過了屏幕..

meteimg = "C:\Users\user\Desktop\meteo.png" 
meteorite = Shapes.AddImage(meteimg) 

meteoriteX = Math.GetRandomNumber(GraphicsWindow.Width) 
Shapes.Move(meteorite, meteoriteX, 0) 
Shapes.Animate(meteorite, meteoriteX, GraphicsWindow.Height,Math.GetRandomNumber(2000)) 

,然後我要補充像

if meteorite's y position > graphicsWindow.height then 
shapes.move(meteorite, meteoriteX, 0) 
endif 
+0

我已經做了這使ufo四處移動,它的工作原理,但運動被推遲..有什麼辦法來解決這個問題嗎? –

回答

1

您不應該爲此使用shapes.animate。移動時無法獲取對象的位置。這裏是astroids的一些代碼:

NumAstroids = 10 
For i = 1 To NumAstroids 
Astroid[i] = Shapes.AddEllipse(20,20) 
AstroidX[i] = Math.GetRandomNumber(GraphicsWindow.Width-20) 
AstroidY[i] = -Math.GetRandomNumber(GraphicsWindow.Height) 
AstroidSpeed[i] = Math.GetRandomNumber(4) + 1 '<- Min speed is 1 
EndFor 

While 1 = 1 
Program.Delay(10) 
For i = 1 To NumAstroids 
Shapes.Move(Astroid[i],AstroidX[i],AstroidY[i]) 
AstroidY[i] = AstroidY[i] + AstroidSpeed[i] 
If AstroidY[i] > GraphicsWindow.Height Then 
    AstroidX[i] = Math.GetRandomNumber(GraphicsWindow.Width-20) 
    AstroidY[i] = -Math.GetRandomNumber(50)-20 
    AstroidSpeed[i] = Math.GetRandomNumber(4) + 1 '<- Min speed is 1 
EndIf 
EndFor 
EndWhile 
+0

非常感謝你,這非常有幫助 –

0
meteorite's y position 

是因爲據我所知等於

Shapes.GetTop(meteorite) 

而且你需要檢查在一個循環,如果它要走動。

+0

我曾與此,在遊戲之前,你必須使用「標誌」,因爲計算機不會更新屏幕,直到發生所有事情。你在使用鍵綁定事件嗎? – Matthew

+0

這可能有一些幫助,點擊此鏈接瞭解延遲和標誌 - > https://social.msdn.microsoft.com/Forums/en-US/86e2da64-5ad7-42d0-9a25-1b72407a85ef/the -pictures-拒收想對節目 - 上 - 這 - 是 - 因爲最延遲我具備的,沒有線索上 - 如何做 - 做這個?論壇= SmallBASIC和#12d0cb19-5161 -41a8-9564-ade533151ab0 – Matthew

+0

沒有標誌是必要的,在這種情況下,我會推薦一個While循環,它定期檢查項目的位置。在最好的情況下,同樣也應該移動它們,所以移動的物品只能定義它們的deltaX和deltaY速度。標誌/事件是用戶的東西,像鼠標點擊。看看這個遊戲:https://mega.nz/#!OJMDWARK!TjgjQzIijkrMOyO_m_O_c1uE413V3BB3n4E8smzPJUI 它是一個塔防護遊戲,我還沒有完成,它不會在你的機器上運行,因爲它需要一些擴展和大量的圖形文件,但裏面你會發現如何在主循環中移動對象的好原則。 – ViteXikora

相關問題