SFML community forums

Help => Graphics => Topic started by: 7krs on July 11, 2012, 08:14:36 pm

Title: Problem Moving Shapes on 'Large' Locations
Post by: 7krs on July 11, 2012, 08:14:36 pm
        MOVX = 1; MOVY = 0;
        RS[0].move(MOVX, MOVY);
 
RS[0].getPosition().x => 1.49598e+008
RS[0].getPosition().y => 0

I found that, at increasing x distances, the value that MOVX requires, to be consistently higher before moving the object at all. I guess it's the same for the y coordinate.

RS is a pointer to sf::RectangleShape, I use sfml 2.0 RC. I check for movement by drawing a background.
Title: Re: Problem Moving Shapes on 'Large' Locations
Post by: Xenir on July 11, 2012, 09:32:17 pm
If the RS is a pointer you shouldn't use "->" instead of "."?
sf::ShapeRectangle * RS;
RS = new sf::ShapeRectangle[n];
RS[0]->move(MOVX, MOXY);
RS[0]->getPosition().x;
RS[0]->getPosition().y;
// do someting else
delete [] RS;
n - some unsigned int value

Edit: Oops, I forget about it. I am accustomed to object-oriented programming, when most of variables are components of class and delete part is, in most cases, in destructor. Sorry for oversight
Title: Re: Problem Moving Shapes on 'Large' Locations
Post by: eXpl0it3r on July 11, 2012, 10:14:29 pm
Stop using raw pointers and arrays, specially if you've actually no idea what you're doing... :-\
But instead use a std::vector and only in certain situation (for sf::ShapeRectangle I can't think of any suitable one) you can use std::unique_ptr or std::share_ptr.

And on top of this all, please switch to SFML 2.0. SFML 1.6 is extremly outdated (last relevant commit was 10th March 2010!) and has some nasty bugs (e.g. ATI bug) where as SFML 2 brings binaries through the release candidate and contains a lot of new usefull features.

Also Xenir if you suggest to someone to use pointers a give a code example don't forget to provide the delete part! ;)

@Topic: Yes that's because SFML is working with floats and they aren't that precies. What are you trying to achive with such big numbers?

Title: Re: Problem Moving Shapes on 'Large' Locations
Post by: 7krs on July 11, 2012, 11:15:32 pm
If the RS is a pointer you shouldn't use "->" instead of "."?

Well, RS is a pointer:
RS = new sf::RectangleShape[50];
 
but only the first element is of interest here.
Only "." seems to work, "->" doesn't, because RS[0] is an actual element, not a pointer, but RS-> would work. But this is an array, so RS-> would point to RS[0].

@Topic: Yes that's because SFML is working with floats and they aren't that precies. What are you trying to achive with such big numbers?

Yea I figured that out. I'm trying to emulate the solar system.