XNA Creators Club Online
Page 1 of 1 (6 items)
Sort Posts: Previous Next

A remove() method?

Last post 21/02/2009 23:28 by worldwaffle. 5 replies.
  • 20/02/2009 16:41

    A remove() method?

    is there something like a remove method, as I'm creating a Pong game. When I hit a brick I want it to dissapear or be removed. Is there something like that?

    if(wallRectangleHit == true)  
    {  
       //something to remove it here.   

    If you can help, thanks!

    <(~!worldwaffle!~)>
  • 20/02/2009 17:02 In reply to

    Re: A remove() method?

    Depends on what you're using to keep track of your brick. If you're using something like a List<Brick> collection, yes, there's a Remove method. You'll need to show us what you're doing for us to offer better feedback.
    Jim Perry - Microsoft XNA MVP
    If people spent a minute searching the forums and reading the FAQs before posting I'd be out of a job.
      Got some XNA Game Studio/XNA Framework development info to share with the community? Put it on the XNA Wiki.
        Please mark posts as Answers or Good Feedback when appropriate.
  • 20/02/2009 19:16 In reply to

    Re: A remove() method?

    In general, you will keep track of everything in your world, for two reasons:
    1) To simulate (run the "game play")
    2) To render

    The simplest way to keep track of everything is to keep a List<Brick> for the bricks, List<Ball> for the ball(s), etc. Then, when you simulate, you iterate over all the bricks and test if a ball is hitting the brick. If so, you add score, play a sound, and remove the brick from the list. Note that there are some rules about modifying collections while you're iterating using foreach(), so you may want to iterate using an integer index instead. Also note that when removing something in a list, every other thing after it slides down one notch, so to not miss the item after the item you remove, you will have to modify the index at that point.

    When you render, you simply render each thing in each list. Because things that were hit are removed from the lists, they won't get rendered, and effectively no longer exist.

    Jon Watte, Direct3D MVP
    Tweets, occasionally
    kW X-port 3ds Max .X exporter
    kW Animation source code
  • 21/02/2009 23:02 In reply to

    Re: A remove() method?

    Thanks. But I have one problem, how would I know which brick in 'List<>' would be getting hit, then how would I call it?

    <(~!worldwaffle!~)>
  • 21/02/2009 23:26 In reply to

    Re: A remove() method?

    Generally, each time the ball moves, you will test it for intersection with each of the bricks, using some collision testing function. BoundingBox.Intersects() comes to mind.

    It sounds to me like you actually ought to follow some of the beginner tutorials on this site, first, though, and perhaps also find a good book on C# programming in general to give you a more solid foundation to stand on before you try to build your own game from scratch.
    Jon Watte, Direct3D MVP
    Tweets, occasionally
    kW X-port 3ds Max .X exporter
    kW Animation source code
  • 21/02/2009 23:28 In reply to

    Re: A remove() method?

    I know enough of C# for now. But anyways... Thanks!

    <(~!worldwaffle!~)>
Page 1 of 1 (6 items) Previous Next