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

Author Topic: Move Sprite in  (Read 1628 times)

0 Members and 1 Guest are viewing this topic.

kol

  • Newbie
  • *
  • Posts: 31
    • View Profile
Move Sprite in
« on: November 06, 2013, 01:02:01 pm »
How can I move sprite int, without giving those locked?
If I put in float, the movement is perfect. But affects the texts, leaving them in blur. What do I do?

My code:

Quote
float x,y,hspeed,vspeed;
hspeed = 0.3;
vspeed = 0.1;

x += hspeed;
y += vspeed;

Player_s.setPosition((int)x,(int)y);

etixpp

  • Jr. Member
  • **
  • Posts: 82
    • View Profile
    • FoxFire Development Website
    • Email
Re: Move Sprite in
« Reply #1 on: November 06, 2013, 01:47:05 pm »
i don´t understand what u want to do.
First of all, if you cast something, do not use c-cast.
Use static_cast<int>(stuff) .
(if u cast number to string reinterpret cast and so on).
But this won´t fix your Problem, Integer´s are only full numbers, so if u cast 0,3 to a integer, it should be downgraded to 0 if i remember right (not sure atm).
Why would you do this?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Move Sprite in
« Reply #2 on: November 06, 2013, 02:02:06 pm »
(if u cast number to string reinterpret cast and so on).
Use C++ casts, but int to string should never be done with such a cast! :o
Either use the C++11 function std::to_string, the boost lexical_cast or std::stringstream.

Why would you do this?
If you use non-integer numbers for positions or the view, OpenGL will work some magic trying to make it look like as if the object was rendered between pixels. This can lead to un-crispy texts, lines between tile maps, etc.

As for the OP, I probably wouldn't cast to integer but simply round the floats, if you however round, I suggest to use sprite.setPosition(static_cast<sf::Vector2f>(first_int, second_int)).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

kol

  • Newbie
  • *
  • Posts: 31
    • View Profile
Re: Move Sprite in
« Reply #3 on: November 06, 2013, 02:10:48 pm »
What a difference:

sprite.setPosition (static_cast <sf :: Vector2f> (first_int, second_int))

for:

sprite.setPosition (int, int)?

-----------------------------------------------------------------------------------------------

If I use int to move the Sprite, it keeps crashing, but if I put in motion float is perfect. However, blur in the text are:

http://i.imgur.com/PGvvA5Z.png