UNKNOWN '************************************** ' Name: Draw a moving starfield on a for ' m ' Description:It draws a moving starfiel ' d on a form with simple VB graphics meth ' ods and a timer control. ' By: Theo Kandiliotis ' ' ' Inputs:None ' ' Returns:None ' 'Assumes:None ' 'Side Effects:None 'This code is copyrighted and has limite ' d warranties. 'Please see http://www.Planet-Source-Cod ' e.com/xq/ASP/txtCodeId.906/lngWId.1/qx/v ' b/scripts/ShowCode.htm 'for details. '************************************** How to draw a moving starfield This example shows how to design a moving star field ,the standard animated background used in most space shoot'em up games.You know,the one that asteroids of all kinds of sizes zip by with various speeds,creating a 3D effect.Here we go: 1.Create a Timer control. 2.Make these settings through the Properties Window: Form1.WindowStart = 2 Form1.Backcolor = &H00000000;& (that's black) Timer1.Interval = 1 3.The algorythm is kinda complicated to explain in spoken words,so I'll leave it up to you to figer out what's going on. Dim X(50), Y(50), pace(50), size(50) As Integer Private Sub Form_Activate() Randomize For I = 1 To 50 x1 = Int(Form1.Width * Rnd) y1 = Int(Form1.Height * Rnd) pace1 = Int(500 - (Int(Rnd * 499))) size1 = 16 * Rnd X(I) = x1 Y(I) = y1 pace(I) = pace1 size(I) = size1 Next End Sub Private Sub Timer1_Timer() For I = 1 To 50 Circle (X(I), Y(I)), size(I), BackColor Y(I) = Y(I) + pace(I) If Y(I) >= Form1.Height Then Y(I) = 0: X(I) = Int(Form1.Width * Rnd) Circle (X(I), Y(I)), size(I) Next End Sub