|
-
May 30th, 2011, 05:50 PM
#1
Thread Starter
Member
2D game help!
Hey everyone!
I've currently working on a game 2D game in Visual Basic 2010 and I need a little bit of help.
I am currently using Pictureboxes for my graphics and user characters. I've figured out a way how to draw them smoothly and efficiently, so please don't say to use e.Graphics
Anyway, I have a random zombie spawn algorithm inside a timer, which makes zombies randomly spawn at different locations withinin the form. I was wondering how I could make an array to add new pictureboxes to the form, and make them move EX:
Code:
Picturebox(x).location = new point(picturebox(x).location.x, picturebox(x).location.y + 3)
The thing is, I would have to do,
Code:
Me.controls.add(picturebox(x))
each time I would want to create a new zombie, which doesn't work.
Thank you for taking your time to read this, I hope you can help 
(Sources, links, examples, code all helps )
-
May 30th, 2011, 07:02 PM
#2
Re: 2D game help!
Given that the list is not of a fixed length, you would use a List(Of PictureBox) rather than an array. That said, whether you use an array or collection, the code you posted will work if there is a PictureBox at that index.
-
May 30th, 2011, 07:19 PM
#3
Thread Starter
Member
Re: 2D game help!
 Originally Posted by jmcilhinney
Given that the list is not of a fixed length, you would use a List(Of PictureBox) rather than an array. That said, whether you use an array or collection, the code you posted will work if there is a PictureBox at that index.
I've tried many different things, none in which seem to work 
Here's my problem with a little bit more detail and revision
(Example of something that could help me out)
I have a button, and when you click that button, it will make 2 pictureboxes appear on the form, and move up.
How would I go about doing this without manually adding pictureboxes to the form?
Thank you
-
May 30th, 2011, 08:40 PM
#4
Re: 2D game help!
 Originally Posted by coldfire417
How would I go about doing this without manually adding pictureboxes to the form?
You wouldn't, unless you had already added the PictureBoxes at design time and set their Visible property to False, which you wouldn't do if you didn't know at design time exactly how many PictureBoxes there were going to be.
There's nothing hard about adding a PictureBox at run time. You create a PictureBox object, set its properties, add it to the Controls collection of the appropriate parent. You can also add it to the aforementioned List(Of PictureBox) if you need to be able to access later.
-
Jun 2nd, 2011, 07:07 PM
#5
Thread Starter
Member
-
Jun 2nd, 2011, 07:33 PM
#6
Re: 2D game help!
Take it one step at a time.
use a List(Of PictureBox)
Show us where you've done that.
You create a PictureBox object
Show us where you've done that.Show us where you've done that.
add it to the Controls collection of the appropriate parent
Show us where you've done that.
add it to the aforementioned List(Of PictureBox)
Show us where you've done that. Each step is very simple. Make sure you are following the steps as described.
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
|