Array of SDL_Surfaces??

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
ibly31
Chaos Rift Junior
Chaos Rift Junior
Posts: 312
Joined: Thu Feb 19, 2009 8:47 pm
Current Project: Like... seven different ones
Favorite Gaming Platforms: Xbox 360, Gamecube
Programming Language of Choice: C++, ObjC
Location: New Jersey.

Array of SDL_Surfaces??

Post by ibly31 »

I'm new to SDL, and I was testing to see if I could display a line of 5 textures I made. It won't let me have an array of surfaces, this is my code:

Code: Select all

std::string tilefile[5] = {"Textures/picket_fence","Textures/picket_fence","Textures/picket_fence","Textures/picket_fence","Textures/picket_fence"};
SDL_Surface *tiles[5]= NULL;

That is the buggy part, but in case you are wondering, I'm going to display them like this:

Code: Select all


for(int i = 0; i < 5; i++){
apply_surface(i*32-32,0,tiles[i],screen);
}
Tiles should be an array of SDL_Surfaces, so I can just blit them.
Tilefile is just the file names of the tiles. I have 29 of them, and I'm going to make a tilesheet soon instead, but This is just a test.
Image
Twitter
Website/Tumblr
My Projects

The best thing about UDP jokes is that I don’t care if you get them or not.
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: Array of SDL_Surfaces??

Post by Ginto8 »

it may be a good idea to make

Code: Select all

SDL_Surface *tiles[5]= NULL;
into

Code: Select all

SDL_Surface *tiles[5] = { NULL, NULL, NULL, NULL, NULL };
so there's no problems with undefined SDL_Surface*'s.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
User avatar
programmerinprogress
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Wed Oct 29, 2008 7:31 am
Current Project: some crazy stuff, i'll tell soon :-)
Favorite Gaming Platforms: PC
Programming Language of Choice: C++!
Location: The UK
Contact:

Re: Array of SDL_Surfaces??

Post by programmerinprogress »

ibly31 wrote:I'm new to SDL, and I was testing to see if I could display a line of 5 textures I made. It won't let me have an array of surfaces, this is my code:

Code: Select all

std::string tilefile[5] = {"Textures/picket_fence","Textures/picket_fence","Textures/picket_fence","Textures/picket_fence","Textures/picket_fence"};
SDL_Surface *tiles[5]= NULL;
[/quote]

are you adding file extensions to the filenames when you load something into the surfaces? 

and I would initialise all of the surfaces to null, as they are pointers, and it is implied that NULL shall not be used by anything, therefore initialising the pointers to NULL prevents any time bombs
---------------------------------------------------------------------------------------
I think I can program pretty well, it's my compiler that needs convincing!
---------------------------------------------------------------------------------------
And now a joke to lighten to mood :D

I wander what programming language anakin skywalker used to program C3-PO's AI back on tatooine? my guess is Jawa :P
User avatar
avansc
Respected Programmer
Respected Programmer
Posts: 1708
Joined: Sun Nov 02, 2008 6:29 pm

Re: Array of SDL_Surfaces??

Post by avansc »

Code: Select all

SDL_Surface **tiles = (SDL_Surface**)malloc(sizeof(SDL_Surface*));

for(int a = 0;a < 5;a++)
{
    tiles[a] = (SDL_Surface*)malloc(sizeof(SDL_Surface));
    // and on with what ever.
}
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
User avatar
ibly31
Chaos Rift Junior
Chaos Rift Junior
Posts: 312
Joined: Thu Feb 19, 2009 8:47 pm
Current Project: Like... seven different ones
Favorite Gaming Platforms: Xbox 360, Gamecube
Programming Language of Choice: C++, ObjC
Location: New Jersey.

Re: Array of SDL_Surfaces??

Post by ibly31 »

what does **tiles do? I thought pointers were only one * ...?

Edit: and I thought malloc and sizeof were only used in C, I'm using C++
Last edited by ibly31 on Mon Mar 09, 2009 4:05 pm, edited 1 time in total.
Image
Twitter
Website/Tumblr
My Projects

The best thing about UDP jokes is that I don’t care if you get them or not.
User avatar
avansc
Respected Programmer
Respected Programmer
Posts: 1708
Joined: Sun Nov 02, 2008 6:29 pm

Re: Array of SDL_Surfaces??

Post by avansc »

ibly31 wrote:what does **tiles do? I thought pointers were only one * ...?
its pointers to pointers.

its for dynamic amount of surfaces.
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
User avatar
ibly31
Chaos Rift Junior
Chaos Rift Junior
Posts: 312
Joined: Thu Feb 19, 2009 8:47 pm
Current Project: Like... seven different ones
Favorite Gaming Platforms: Xbox 360, Gamecube
Programming Language of Choice: C++, ObjC
Location: New Jersey.

Re: Array of SDL_Surfaces??

Post by ibly31 »

IS each surface an image or am I drawing 5 diefferent surfaces when it could just be one?

Oh, and it works, thanks!1one one
Image
Twitter
Website/Tumblr
My Projects

The best thing about UDP jokes is that I don’t care if you get them or not.
Post Reply