Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - lowps

Pages: [1]
1
Graphics / Re: Rotating sprite around its center AND resizing it
« on: April 07, 2012, 09:46:46 pm »
Thanks -- I realize that makes more sense now. I've looked around the forum and some other places and most people seem to use (or imply they use) sprite.SetCenter( sprite.GetSize() / 2.f ), which would work only if the sprite has not been resized already. Maybe it's better to use:
Code: [Select]
if( sprite.GetImage() )
   sprite.SetCenter( sprite.GetImage()->GetWidth / 2, sprite.GetImage()->GetHeight / 2 )
because it will work regardless of when the image was resized?

Thanks again!

2
Graphics / Rotating sprite around its center AND resizing it
« on: April 07, 2012, 09:42:45 am »
I am using SFML 1.6 and am trying to rotate a resized sprite about its center. Rotating about a sprite's center seems to work fine if the sprite is not resized, but when resized, SetCenter() does not seem to place the sprite's center at the proper place, and the sprite ends up rotating about some other point.
For example, the following code is in my main game loop, as a test:
Code: [Select]
sf::Sprite test( ImageCache::GetImage("simple_bit.png") );
  float rotation = 0;
  test.SetPosition( 300, 300 );
  //test.Resize( 50, 50 );                                                                                                                                                                                                         
  test.SetCenter( test.GetSize() / 2.f );
  test.SetRotation( rotation++ );
  screen.Draw( test );

This will work fine, and the sprite will appear to rotate about its center. Yet if the call to Resize() is uncommented, the sprite will seem to rotate around a point that is slightly off its center. The greater the difference between the resized sprite and the original image, the greater the distance between the desired axis and the axis I get.

The only reason I could think this would happen is if SetCenter() sets the center of the sprite in relation to the size of the Image, not the sprite. Some tests I have done seem to indicate this. If this is actually the issue, then this needs to be made more clear in the forums and tutorials (unless I'm just blind).

Am I missing anything?

Pages: [1]
anything