Discussion Board

Results 1 to 2 of 2
  1. #1
    Regular Contributor
    Join Date
    Sep 2003

    creating new instances.

    I'm creating a small shoot 'em up game for 7210 and have created a Laser class which will is responsible for painting and moving the laser sprite.

    Is it best to create a fixed size array of, say 10 Laser, items and kill and revive these as the game is played or is it best to create new instances of the laser class each time the fire button is pressed(i.e. have a vector of Laser objects... no array... that I create new and delete old Laser items from the list as the game is played)?

    Basically, is one way faster than the other? I assume there must be some overhead creating the Laser instances as the player hits the fire button? So I thought the fixed array would be faster?

    And ideas would be helpful. Thanks.

  2. #2
    Super Contributor
    Join Date
    Mar 2003
    The fixed array is faster. The disadvantage is that you can't have more than 10 shots. In general, you should keep object creation (and object destruction~garbage creation) to a minimum, since creating new objects is expensive and collecting the garbage you're creating is also expensive.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts