Results 1 to 6 of 6

Thread: 2D game help!

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2009
    Posts
    55

    Exclamation 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 )

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2009
    Posts
    55

    Re: 2D game help!

    Quote Originally Posted by jmcilhinney View Post
    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

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: 2D game help!

    Quote Originally Posted by coldfire417 View Post
    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Member
    Join Date
    Oct 2009
    Posts
    55

    Question Re: 2D game help!

    Hmm... I cant seem to figure it out

    Maybe you could provide sample code?

    Thanks!

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    set its properties
    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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
  •  



Click Here to Expand Forum to Full Width