Jump to content
  • Advertisement
Sign in to follow this  
Afr0m@n

Putting data into arrays?

This topic is 4893 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

Quote:
Original post by TyroWorks
How about this to create the array of objects:

player_imgs = new SDL_Surface *[7];

See this thread:
LINK


He should only need to do that if he is allocating an array of non-constant size.

Share this post


Link to post
Share on other sites
Advertisement
Thanks guys now there's only one error remaining! :) This is what the compiler says:

[source lang ="cpp"]--------------------Configuration: SDL DrawImage test - Win32 Debug--------------------
Compiling...
main.cpp
C:\Programs\C++\SDL\SDL DrawImage test\main.cpp(19) : error C2440: 'initializing' : cannot convert from 'struct SDL_Surface *' to 'unsigned int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\Programs\C++\SDL\SDL DrawImage test\main.cpp(92) : warning C4018: '>' : signed/unsigned mismatch
Error executing cl.exe.

SDL DrawImage test.exe - 1 error(s), 1 warning(s)



This error is really freakign me uot since I've loaded bmps into SDL_Surfaces before! :S

Share this post


Link to post
Share on other sites
The type of the variable you're initializing has to be filled in (or it defaults to int) and match what you're initializing with (SDL_Surface*).

Enigma has it correct:

SDL_Surface * player_imgs[7] = {SDL_LoadBMP("Graphics/Ships/Player/anim/pl_left01.bmp")};


That is an array of pointers, which is initialized (not assigned to) using the result of the LoadBMP() call (that result is a pointer of the type you want) for element 0 and null pointers for the others.

BTW, that signed/unsigned mismatch could be a severe problem - it may result in comparisons not behaving the way you expect. There's a good chance there's a variable that you should be declaring as unsigned whereas it is currently signed (the default for short/int/long) or vice-versa.

Share this post


Link to post
Share on other sites
I would not recommend calling SDL_LoadBMP at initialisation time. This function will be called before you initialise SDL. In this particular case, SDL_LoadBMP probably doesn't require SDL to be initialised, so it runs okay, but it's a bad habit to get into.

More info: here and here.

cheers
sam

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!