Yes i have been asking for help quite alot but this is just wierd! Take my code below:
vb Code:
Private Sub ItemSpawner_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ItemSpawn.Tick Dim Spawn, X, Y As Integer Dim Item As PictureBox Dim Placeable As Boolean Dim Objects As Control Placeable = True Randomize() Spawn = (Rnd() * 20 + 1) Background.SendToBack() Select Case Spawn Case Is = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 'FireBall Do Item = New PictureBox Item.Image = Image.FromFile("FireBall.gif") '<<<--- Also Freezes at this point sometimes. Item.Width = 26 Item.Height = 30 Controls.Add(Item) X = (Rnd() * 760 + 1) Y = (Rnd() * 560 + 1) Item.Location = New Point(X, Y) '<<<--- Freezes at this point on repeat! Item.Tag = "Item Fireball" For Each Objects In Controls If TypeOf Objects Is PictureBox AndAlso Objects.Tag = "wall" Then If Objects.Bounds.IntersectsWith(Item.Bounds) Then Placeable = False End If End If Next Objects Loop Until Placeable = True Item.Visible = True End Select End Sub
It runs the code 1st time well but on the loop it freezes. So it'll place the object fine and it it does not collide with anything, the code passes on and all i well. However if the object the placed and it collides, i tell it to reposition be looping the code again. This causes problems... the program just Freezes! No error, just freeze!
I just cant see what is causing this. To me, the code although not Perfect, should work.
can anyone see what is wrong with it?
If requested, ill pm source files since this is my groups assignment.




Reply With Quote