A stupid SDL_Surface height and width question

Started by
4 comments, last by zacaj 12 years, 8 months ago
I am making a simple Pong game in C++ with SDL and I need to get the height and width of my Sprite and I should be able to get that from my SDL_Surface * that is the visual representation of the Sprite.

Now I am doing that right now simply by doing it like this:


h = opPicture -> h;
w = opPicture -> w;


Where opPicture is the SDL_Surface in question.

But I get some really weird values as a result.

Am I doing it wrong, is there another way to get those values?
Advertisement
That should work. What format are h and w, and how are you creating the surface? What kind of results are you getting?

That should work. What format are h and w, and how are you creating the surface? What kind of results are you getting?


Ok first I have to explain that the SDL_Surface * exists in a class called Image that also keeps controll of the refcount of the surface amongst other things which the Sprite class then uses.

Height and width are both Integers.

Now when I set the height and width in the Image constructor they become when I tested it: 375 and 100 in height and width respectively.
That looks right to me. So I checked what that value becomes when it gets to the Sprite class and it then turns into: 8 and 1970344334.
That's a big difference.
So then the Sprite class must have a member thats a SDL_Surface, is the SDL_Surface->w still right? Is the Sprites dimensions ever right?

So then the Sprite class must have a member thats a SDL_Surface, is the SDL_Surface->w still right? Is the Sprites dimensions ever right?


Ok, just to clarify. I set two integers in Image, h and w, from the height and width from the SDL_Surface *. At that point the values are correct.

But then in the Sprite class I call two methods in Image that returns the height and width from Image. And it is from that point that the values gets all wrong.
So yes. The values are at one point right.

*Edit*

I still have not figured out why it did not work as it should but I have found a workaround. Instead of sending the height and width from Image to Sprite I retrieve the surface from Image
and then in sprite does "surface -> w;" and "surface -> h;"

And that works.
Can you post the Image::function that returns the dimensions?

This topic is closed to new replies.

Advertisement