-
Jun 6th, 2017, 08:06 PM
#1
Thread Starter
Member
[RESOLVED] MonoGame Images Not Added To List From For Loop
The problem I am having is that when I am using the Load Sub, the For Loop does not add images to the list, as seen by the Message Box of the Count Property of the List(bswimages)(Returns 0). How do I fix my code in order to have the images put in the list. Thanks in advance.
Code:
Private bswimages As New List(Of Texture2D)()
Protected Overrides Sub LoadContent()
' Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = New SpriteBatch(GraphicsDevice)
' TODO: use this.Content to load your game content here
'Load BShooterWalk Animation Content (pngs)
Dim bswimages As New List(Of Texture2D)()
Dim bswfolderPath As String = "Images/BShooterWalk/"
For i As Integer = 0 To 33
Try
If i <= 9 Then
bswimages.Add(Content.Load(Of Texture2D)(bswfolderPath & "bshooter_" & "00" & i & Convert.ToString(i.ToString)))
Else
bswimages.Add(Content.Load(Of Texture2D)(bswfolderPath & "bshooter_" & "0" & i & Convert.ToString(i.ToString)))
End If
Catch
Exit Try
End Try
Next
MsgBox(bswimages.Count)
End Sub
-
Jun 6th, 2017, 08:24 PM
#2
Re: MonoGame Images Not Added To List From For Loop
It's because you defined two variables with the same name... one outside the sub (presumably at the class level) and one INSIDE the sub... so when you then reference your list, it thinks you want the one inside the sub... so it loads the images into it... but when the sub then exits, the variable goes with it, leaving you with your empty, class level one.
So the solution is simple... remove the bswimages declaration in the sub.
-tg
-
Jun 6th, 2017, 09:24 PM
#3
Thread Starter
Member
Re: MonoGame Images Not Added To List From For Loop
Even with the bswimages declaration in the sub removed, the msgBox gives me a value of 0.
-
Jun 7th, 2017, 06:49 AM
#4
Re: MonoGame Images Not Added To List From For Loop
THen there's an error happening... but your catch doesn't deal with errors, it simply exits. That's the equivalent to an On Error Resume Next... Take out the TRy Catch and see if you get any errors.
tg
-
Jun 7th, 2017, 08:47 PM
#5
Thread Starter
Member
Re: MonoGame Images Not Added To List From For Loop
Thank you! My problem was solved.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|