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

Author Topic: Problem Moving Shapes on 'Large' Locations  (Read 1852 times)

0 Members and 1 Guest are viewing this topic.

7krs

  • Newbie
  • *
  • Posts: 39
    • View Profile
    • Email
Problem Moving Shapes on 'Large' Locations
« 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.
« Last Edit: July 11, 2012, 08:17:37 pm by 7krs »

Xenir

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Problem Moving Shapes on 'Large' Locations
« Reply #1 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
« Last Edit: July 11, 2012, 11:18:58 pm by Xenir »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10038
    • View Profile
    • development blog
    • Email
Re: Problem Moving Shapes on 'Large' Locations
« Reply #2 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?

« Last Edit: July 11, 2012, 10:20:25 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Nightly Builds: https://www.nightlybuilds.ch/
——————————————————————
Dev Blog: https://dev.my-gate.net/
Thor: http://www.bromeon.ch/libraries/thor/

7krs

  • Newbie
  • *
  • Posts: 39
    • View Profile
    • Email
Re: Problem Moving Shapes on 'Large' Locations
« Reply #3 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.
« Last Edit: July 11, 2012, 11:39:43 pm by 7krs »