SFML community forums
Help => Graphics => Topic started by: dewyatt on July 06, 2008, 06:46:26 pm
-
I know that SetRotationCenter, etc, have all been combined into SetCenter in 1.3.
So I changed all my calls to use SetCenter but I just noticed it doesn't seem to be working correctly.
It looks like everything is rotating around it's top-left corner.
Here's some code:
mSprite.SetImage(theGlyph->Texture);
mSprite.SetPosition(static_cast<float>(x), static_cast<float>(y));
mSprite.SetSubRect(sf::IntRect(0, 0, theGlyph->Texture.GetWidth(), theGlyph->Texture.GetHeight()));
mSprite.SetCenter(0.5f * theGlyph->Texture.GetWidth(), 0.5f * theGlyph->Texture.GetHeight());
mSprite.SetRotation(mRotation);
mSprite.SetScaleX(mHScale);
mSprite.SetScaleY(mVScale);
mWindow->Draw(mSprite);
It's from my sfmlTTF library (which is more appropriate for my game than sf::String).
-
well, you actually set your center at a top-left pixel of your sprite, so I'd say rotating around it's left corner is actually correct...
-
Sorry, wrong code.
Changed it.
-
mhhh, are you sure there is a GetWidth()-Method for Sprites?
I can't find one in the Doc, try using GetSize().x and GetSize().y instead...
-
The problem is you're getting the width of the image rather than the sprite. (which is a sub-rectangle of the image)
EDIT: Also, for consistency reasons, shouldn't sf::Image also use the GetSize method?
-
Well I'm reusing the sprite.
And It's not really a sub-rectangle, it uses the full image:
mSprite.SetSubRect(sf::IntRect(0, 0, theGlyph->Texture.GetWidth(), theGlyph->Texture.GetHeight()));
The 'Texture' is an sf::Image.
This all worked fine with 1.2.
-
I don't know 1.2, but reading the documentation of 1.3, I'm not able to find GetWidth() or GetHeight() for either Sprites or Images. (What is what I expected, since I've never before used GetWidth()/Height() ...)
Did you try GetSize().x and GetSize().y? These Methods should give you the Height and Width!
-
So this was intentional?
mSprite.SetCenter(0.5f * theGlyph->Texture.GetWidth(), 0.5f * theGlyph->Texture.GetHeight());
I would think you would want to do this:
mSprite.SetCenter(0.5f * mSprite.GetSize().x, 0.5f * mSprite.GetSize().y);
I don't know 1.2, but reading the documentation of 1.3, I'm not able to find GetWidth() or GetHeight() for either Sprites or Images. (What is what I expected, since I've never before used GetWidth()/Height() ...)
Did you try GetSize().x and GetSize().y? These Methods should give you the Height and Width!
GetWidth() does exist for sf::Image.
EDIT: I see you edited your post and I get it now. :P
So is SetSubRect() even needed?
-
So this was intentional?
mSprite.SetCenter(0.5f * theGlyph->Texture.GetWidth(), 0.5f * theGlyph->Texture.GetHeight());
I would think you would want to do this:
mSprite.SetCenter(0.5f * mSprite.GetSize().x, 0.5f * mSprite.GetSize().y);
That does seem to be correct.
I'm guessing sf::Sprite::GetSize returns the transformed size?
EDIT: I see you edited your post and I get it now. :P
So is SetSubRect() even needed?
Yes, I edit quick and often. :)
I believe SetSubRect is needed because I'm re-using the sprite with different sf::Images all the time.
I seem to recall it crashed if I didn't use SetSubRect().
I still haven't figured this out, I'm trying though.
-
I looked through older version of my code and tried using some of the older code.
It's still not working.
I have test programs for sfmlTTF that were linked with SFML 1.2 and things rotate as expected.
I think something changed or broke from SFML 1.2/1.3.
I'm still testing things.
-
EDIT: Son of a B.
I knew one day I would make one of these moronic mistakes.
I've been recompiling but using my old executable because I had copied it from "Debug/" to "/".
This is why I always change my projects to output to $(SolutionDir).
So I don't need to load resources with "../" or copy the exe to "../".
OKAY, i'm going to try to confirm I can fix this now.
-
Yeah, fixed it.
I can't even remember what I changed.
The final code is like this:
mSprite.SetImage(theGlyph->Texture);
mSprite.SetSubRect(sf::IntRect(0, 0, theGlyph->Texture.GetWidth(), theGlyph->Texture.GetHeight()));
mSprite.SetPosition(static_cast<float>(x), static_cast<float>(y));
mSprite.SetCenter(mRotationCenterX * mSprite.GetSize().x, mRotationCenterY * mSprite.GetSize().y);
mSprite.SetRotation(mRotation);
mSprite.SetScaleX(mHScale);
mSprite.SetScaleY(mVScale);
mWindow->Draw(mSprite);
I'm so pissed I wasted my time and your time on this.
I've been programming for way to long to make these type of mistakes.
Oh well, I guess I'm just tired.
Somewhere along the line this caused glyphs to not be drawn on the baseline.
I'll have to figure that out now.