Public Group

A stupid SDL_Surface height and width question

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

Recommended Posts

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?

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

Share on other sites

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.

Share on other sites
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?

Share on other sites

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.

Share on other sites
Can you post the Image::function that returns the dimensions?

1. 1
2. 2
Rutin
22
3. 3
4. 4
JoeJ
17
5. 5

• 14
• 30
• 13
• 11
• 11
• Forum Statistics

• Total Topics
631774
• Total Posts
3002297
×