Sign in to follow this  

A stupid SDL_Surface height and width question

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

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:

[code]
h = opPicture -> h;
w = opPicture -> w;
[/code]

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 this post


Link to post
Share on other sites
[quote name='zacaj' timestamp='1312470981' post='4844527']
That should work. What format are h and w, and how are you creating the surface? What kind of results are you getting?
[/quote]

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 this post


Link to post
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 this post


Link to post
Share on other sites
[quote name='zacaj' timestamp='1312476088' post='4844561']
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?
[/quote]

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 this post


Link to post
Share on other sites

This topic is 2324 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this