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

Author Topic: Movement Issue  (Read 1466 times)

0 Members and 1 Guest are viewing this topic.

Linux Vs God

  • Newbie
  • *
  • Posts: 18
    • View Profile
Movement Issue
« on: July 29, 2011, 08:14:39 pm »
Whenever i press the Left, Right, Up, or Down buttons, my sprite moves in those directions. However, when i press one of the buttons the sprite moves to that direction for one second, then it pauses and then it starts to move. Heres my movement code:

Code: [Select]
if(App.GetInput().IsKeyDown(sf::Key::Up))
    {
        spriteFrameUp++;

        if(spriteFrameUp > 1)
            Link.SetImage(linkup2);
        if(spriteFrameUp > 2)
            Link.SetImage(linkup3);
        if(spriteFrameUp > 3)
            Link.SetImage(linkup4);
        if(spriteFrameUp > 4)
            Link.SetImage(linkup5);
        if(spriteFrameUp > 5)
            Link.SetImage(linkup6);
        if(spriteFrameUp > 6)
            Link.SetImage(linkup7);
        if(spriteFrameUp > 7)
            Link.SetImage(linkup8);
        if(spriteFrameUp > 8)
            spriteFrameUp = 0;

        Link.Move(0, -velocity);
    }

    if(App.GetInput().IsKeyDown(sf::Key::Down))
    {
        spriteFrameDown++;

        if(spriteFrameDown > 1)
            Link.SetImage(linkdown2);
        if(spriteFrameDown > 2)
            Link.SetImage(linkdown3);
        if(spriteFrameDown > 3)
            Link.SetImage(linkdown4);
        if(spriteFrameDown > 4)
            Link.SetImage(linkdown5);
        if(spriteFrameDown > 5)
            Link.SetImage(linkdown6);
        if(spriteFrameDown > 6)
            Link.SetImage(linkdown7);
        if(spriteFrameDown > 7)
            Link.SetImage(linkdown8);
        if(spriteFrameDown > 8)
            spriteFrameDown = 1;

        Link.Move(0, velocity);
    }

    if(App.GetInput().IsKeyDown(sf::Key::Right))
    {
        spriteFrameRight++;

        if(spriteFrameRight > 1)
            Link.SetImage(linkright2);
        if(spriteFrameRight > 2)
            Link.SetImage(linkright3);
        if(spriteFrameRight > 3)
            Link.SetImage(linkright4);
        if(spriteFrameRight > 4)
            Link.SetImage(linkright5);
        if(spriteFrameRight > 5)
            Link.SetImage(linkright6);
        if(spriteFrameRight > 6)
            Link.SetImage(linkright7);
        if(spriteFrameRight > 7)
            Link.SetImage(linkright8);
        if(spriteFrameRight > 8)
            spriteFrameRight = 1;

        Link.Move(velocity, 0);
    }

    if(App.GetInput().IsKeyDown(sf::Key::Left))
    {
        spriteFrameLeft++;

        if(spriteFrameLeft > 1)
            Link.SetImage(linkleft2);
        if(spriteFrameLeft > 2)
            Link.SetImage(linkleft3);
        if(spriteFrameLeft > 3)
            Link.SetImage(linkleft4);
        if(spriteFrameLeft > 4)
            Link.SetImage(linkleft5);
        if(spriteFrameLeft > 5)
            Link.SetImage(linkleft6);
        if(spriteFrameLeft > 6)
            Link.SetImage(linkleft7);
        if(spriteFrameLeft > 7)
            Link.SetImage(linkleft8);
        if(spriteFrameLeft > 8)
            spriteFrameLeft = 1;

        Link.Move(-velocity, 0);
    }

Contadotempo

  • Full Member
  • ***
  • Posts: 167
  • Firelink Shrine
    • View Profile
Movement Issue
« Reply #1 on: July 29, 2011, 08:46:32 pm »
Hi,
Since you're dealing with real-time input be sure to leave that part of the code out of the GetEvent() loop.
Don't know if that's the case here but here's an example if it is:

Code: [Select]
while(App.IsOpened())
{
               
sf::Event eventUI;

// THIS IS THE EVENT LOOP:
while(App.GetEvent(eventUI))
{
if(eventUI.Type == sf::Event::Closed)
App.Close();

if(eventUI.Type == sf::Event::MouseButtonPressed && eventUI.MouseButton.Button == sf::Mouse::Left)
Fire();
}

// THIS IS A REAL-TIME INPUT:
if(App.GetInput().IsKeyDown(sf::Key::Up))
GoUP();
}

Linux Vs God

  • Newbie
  • *
  • Posts: 18
    • View Profile
Movement Issue
« Reply #2 on: July 29, 2011, 08:50:44 pm »
Thanks it worked!