Hi,
Ive recently been using SDL(for graphics and sound) to create a game.
Ive been using LazyFoos tutorials and everything works as expected.
My problem is that with like 20 buttons in the game the "clips" take up a lot of space.
I was wondering if i could just create a separate .cpp file just for the clips and include it
or whether i should create a .txt file and read the clips from that although i'm unsure how to do this.
You are using lazyfoo's button class? If each kind of button is stored in different images you could let the button class store the 4 clips as an array inside the class, and have the them initialized in the constructor.
Hey,
Thanks for the reply :)
Sorry i dont think you understood what i meant.
I have made my own class and i already have a function to pass the clips to the class.
Its just that writing the clips in main takes up a lot of space and looks untidy and i was just wondering where i could store them out of the way.
I dont know if you're allowed to include a .cpp or if there are problems with it. And i have always been told not to assign values in a header.
No i have multiple images.
They are different sizes though so i have different clips for each one.
So i would have to create multiple SDL_Rects to make them and this looked messy.
Sorry if there was a misunderstanding :)
But yeah i think that extern may be what i was looking for.
Im going to look it up now.
Peter87 wrote:
I just thought that there might be a way to automate the creation of the clips.
I was just saying i already had a function to read in the clips i had made
If the clips for each button has the same size and the clips is stored in the same order for all clips you could calculate the clips from the width and height of the button. This could be calculated in the constructor and stored in an array or it could be calculated on the fly when the button is drawn.
Had you looked at using SFML ? It is a C++ library , cross-platform , easier , less messier , faster and probably recent.
P.S : I dont want any arguments over sdl vs sfml ,any flames etc.I am suggesting my opinion.
The buttons are all different sizes which was why i was having a problem.
I have changed it so the clips are calculated in the constructor though.
Extern also helped with my other problem.
So thank you :)