1 Replies - 3520 Views - Last Post: 12 December 2012 - 08:41 AM Rate Topic: -----

#1 AshinoxVGs  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 11-December 12

How do I spawn multiple image boxes with an array?

Posted 11 December 2012 - 05:34 PM

First, I'd like to start off by saying I like to bite off more than I can chew... metaphorically, of course

I've been working on a project for my Computer Science class. It's a 2-D Shoot-em-up Platformer. I've been blasting through it easily, coding up a storm... until I hit the Monster Generator. I've been trying multiple ideas, but to no avail, and the my friend (coding a Tower Defense in VB Express 2010) shows me his game and he's got monsters spawning from one side and walking to the other, following his path.

I've got my array started but I can't get my monsters to spawn.

The code that I have right now for my array is...
    Dim i As Integer = 19
    Dim Bats(i) As PictureBox
    Dim Slime(i) As PictureBox


and in my spawning timer
        For Me.i = 1 To 1
            Bats(i).Location = New Point(12, 500)
            Bats(i).Size = New Size(50, 50)
            Bats(i).BackgroundImage = My.Resources.Bat
            Slime(i).Location = New Point(666, 415)
            Slime(i).Size = New Size(50, 25)
            Slime(i).BackgroundImage = My.Resources.slime
        Next i


I'm fairly new to coding but I know what I'm doing (well... sort of). I just want to get past this little speed bump. I have 8 days to finish this and this is the only part I've had trouble with.

I get the feeling that one of you are going to look at what I have and your eye will twitch, but I'm trying my hardest and all I want it to do is make mobs come from both the left and the right. Thanks in advance and I'm looking forward to a response. If you guys need anymore code -for reasons I cannot fathom... but that's just me-, I'll be more than happy to supply it.

-Ash

View PostAshinoxVGs, on 11 December 2012 - 05:30 PM, said:

Words.



I realize I posted this in the wrong Forum. I apologize in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: How do I spawn multiple image boxes with an array?

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5535
  • View blog
  • Posts: 11,857
  • Joined: 02-June 10

Re: How do I spawn multiple image boxes with an array?

Posted 12 December 2012 - 08:41 AM

You made an array. But its empty. You have to make new PictureBoxes for each element.

Bats(i) is initially empty/null until you make a new picture box and assign it to that element. Something similar to:
Dim pb as PictureBox
Bats(i) = pb


I don't follow VB much but it sure looks like your loop only goes from 1 to 1 - which seems a waste of a loop.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1