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

Author Topic: Improving moving with Rclick?  (Read 1897 times)

0 Members and 2 Guests are viewing this topic.

SEnergy

  • Newbie
  • *
  • Posts: 20
    • View Profile
Improving moving with Rclick?
« on: September 12, 2012, 04:10:29 pm »
I've been doing this thing today and I encountered weird problem, when I go down-right(+X, +Y)(case 5) or any other direction my Sprite (pPlayer) is "bugged", when I click again (I didn't move mouse) after he arrives where he is supposed to be, he somehow "shakes" himself(he is moving to some direction and then opposite direction in less than ~0.3sec)  when I go to other directions my player will move a little bit further and when I click again on that same spot (without moving with mouse) after he arrives it will "come back" to the right spot (where mouse is), since he is always like +2X/+2Y away

Vector2f Poss = pPlayer.getPosition();
                        if(bGo)
                        {
                                HWND hOutput = GetDlgItem(hWnd, IDC_OUTPUT1);
                                SendMessage(hOutput, WM_SETTEXT, NULL, (LPARAM) "true");
                                switch(rot)
                                {
                                case 5: // dole v pravo
                                        {
                                                if((Go.y - Poss.y) > Speed*ElapsedTime && (Go.x - Poss.x) > Speed*ElapsedTime)
                                                        pPlayer.Move(Speed*ElapsedTime, Speed*ElapsedTime, a);
                                                else if((Go.x - Poss.x) > Speed*ElapsedTime)
                                                {
                                                        pPlayer.Move(Speed*ElapsedTime, 0, a);
                                                        if((Go.y - Poss.y) > Speed*ElapsedTime)
                                                                pPlayer.Move(0, Speed*ElapsedTime, a);
                                                }
                                                else if((Go.y - Poss.y) > Speed*ElapsedTime)
                                                {
                                                        pPlayer.Move(0, Speed*ElapsedTime, a);
                                                        if((Go.x - Poss.x) > Speed*ElapsedTime)
                                                                pPlayer.Move(Speed*ElapsedTime, 0, a);
                                                }
                                                else
                                                {
                                                        SendMessage(hOutput, WM_SETTEXT, NULL, (LPARAM) "false");
                                                        bGo = false;
                                                }
                                                break;
                                        }
                                }
                        }
« Last Edit: September 12, 2012, 04:45:01 pm by SEnergy »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Improving moving with Rclick?
« Reply #1 on: September 12, 2012, 04:34:55 pm »
I don't understand at all what the problem is... ???
Try to minimize the code by removing bits that don't have anything to do with the problem and post that minimal and complete code. Not many if any will look at your hugh listing...
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

SEnergy

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Improving moving with Rclick?
« Reply #2 on: September 12, 2012, 04:45:17 pm »
done, hope it's enough, can't explain it simplier

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Improving moving with Rclick?
« Reply #3 on: September 12, 2012, 05:07:57 pm »
The code is not complete, i.e. I can't go copy&paste it into a file, compile and run it... ;)

Also since it's not complete we don't know what you do before, e.g. how's the mouse clicks handled that you're referring to, or what Go is...
Additionally you said what goes wrong, but you didn't say how the sprite should behave, e.g. what you want to achieve with that code.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

SEnergy

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Improving moving with Rclick?
« Reply #4 on: September 12, 2012, 05:43:16 pm »
ok so I right click to get coords of mouse in window, then I'll set bGo to true and Go Vector to coords of mouse -half of the size of texture, so the middle of the texture will go to that point and set rotation

lets say I clicked on coords 100,200, and I'm on 200,400, therefore I'll go top left, so my rotation will be case 10 since it's left (2) and top ( 8 )

/*your code for window(RenderWindow) and player here - MainWindow & pPlayer*/
Vector2i Go;
bool bGo = false;

const float Speed = 75.f;
Clock clock;

int rot;

//message stuff

float ElapsedTime = clock.getElapsedTime().asSeconds();
                        clock.restart();
if(Mouse::isButtonPressed(Mouse::Right))
                        {
                                Go = Mouse::getPosition(MainWindow);
                                Vector2u size = pPlayer.getSize();
                                size.x /= 2;
                                size.y /= 2;
                                Go.x -= size.x;
                                Go.y -= size.y;
                                if(Go.x > Poss.x)
                                        rot += 1;
                                if(Go.x < Poss.x)
                                        rot += 2;
                                if(Go.y > Poss.y)
                                        rot += 4;
                                if(Go.y < Poss.y)
                                        rot += 8;
                        }

case 10:
                                        {
                                                if((Go.y - Poss.y) < Speed*ElapsedTime && (Go.x - Poss.x) < Speed*ElapsedTime)
                                                        pPlayer.Move(-Speed*ElapsedTime, -Speed*ElapsedTime, a);
                                                else if((Go.x - Poss.x) < Speed*ElapsedTime)
                                                {
                                                        pPlayer.Move(-Speed*ElapsedTime, 0, a);
                                                        if((Go.y - Poss.y) < Speed*ElapsedTime)
                                                                pPlayer.Move(0, -Speed*ElapsedTime, a);
                                                }
                                                else if((Go.y - Poss.y) < Speed*ElapsedTime)
                                                {
                                                        pPlayer.Move(0, -Speed*ElapsedTime, a);
                                                        if((Go.x - Poss.x) < Speed*ElapsedTime)
                                                                pPlayer.Move(-Speed*ElapsedTime, 0, a);
                                                }
                                                else
                                                {
                                                        bGo = false;
                                                }
                                                break;
                                        }


BUT after he moves there he is like 98, 198, which is -2X and -2Y away from "destination", but this occurs only when I go more like 5pixels... and after I click again to 100,200 he will move there since he is close to it...
« Last Edit: September 12, 2012, 05:45:27 pm by SEnergy »

 

anything