Jump to content
  • Advertisement
Sign in to follow this  

Dynamic arrays

This topic is 5131 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have code like such

//contains the frames of animation -- Walking
       Frame Animation_Walk_Left[3];
       Frame Animation_Walk_Right[3];
       Frame Animation_Walk_Up[3];
       Frame Animation_Walk_Down[3];

       //contains the frames of animation -- fighting
       Frame Animation_Fight_Left[3];
       Frame Animation_Fight_Right[3];
       Frame Animation_Fight_Up[3];
       Frame Animation_Fight_Down[3];

       //contains the frames of animation -- Running
       Frame Animation_Run_Left[3];
       Frame Animation_Run_Right[3];
       Frame Animation_Run_Up[3];
       Frame Animation_Run_Down[3];

       //contains the frames of animation -- Die
       Frame Animation_Die_1[3];
       Frame Animation_Die_2[3];
       Frame Animation_Die_3[3];

But I want the the Animation sequences' size to be able to change, not stay locked at 3 members. In VB we ReDimmed the arrays. Can you do this in C++? I've never really had to do this before. Well..I did once, and I used vectors I think, and that was slow/painful. FYI, i'm using BCB 6. Also, would the template contained in sysdyn.h work fast enough for a game? Cheers Sigma

Share this post

Link to post
Share on other sites
The best way is using std::vector. The speed overhead is really small so don't care.

std::vector<Frame> Animation_Walk_Left(3);

//blah blah

//Insert a new element
Frame MyNewFrame;

If you don't change the dimensions of the array often, you could also use a pointer, but if you do you will have to deallocate and reallocate memory, and it's going to be slow if you do this every frame.

Frame* Animation_Walk_Left = new Frame[3];

//use this like an array

//Destroy it and recreate to change the size
delete[] Animation_Walk_Left;
Animation_Walk_Left = new Frame[5];

Share this post

Link to post
Share on other sites
I thought they were kinda slow....Besides, i'm only resizing once. So linked list would be overkill I think

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!