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

Author Topic: Sprite flickering / going back  (Read 1277 times)

0 Members and 1 Guest are viewing this topic.

cadeyrn

  • Newbie
  • *
  • Posts: 1
    • View Profile
Sprite flickering / going back
« on: December 24, 2017, 05:50:40 pm »
Hello!

I'm currently re-creating an old game that's using a grid based movement.
I've currently creating a login window that connects to the server and the server then checks if the username & password are correct, etc etc. It returns the player position on the overworld map allowing the client to render the screen with the player sprite in the middle (facing its right direction).

The player can correctly move around, including the animation (there's only one static animation image and one moving animation image). It receives a list of players online and where they're at + the way they're facing, and also renders those.

When you move, it updates the position on the server as well, the server lets other players know that player started moving.

What works:
- If the player moves, it updates correctly on the player's screen

- If someone else moves, it updates correctly on your own screen

What doesnt work:
If you and someone else move in the same direction-ish, there's like a slight flicker backwards during the 'half-step' between the grid tiles, only for the other player. Like, it moves to half step, then seems to flicker back very quickly to its previous position, back to half step and then to the end position.

I think it has to do with that I'm moving the map in the opposite direction of where the player is moving, I'm not sure.

Code:
window:
// PROCESS EVENTS
client->ProcessEvents(elapsedTime);

// Clear the screen
window.clear(sf::Color::Black);

// Second layer tiles
for each(TileRow row in client->map.tileRows)
{
        for each(TileColumn column in row.tileColumns)
       {
                // Draw the second layer tile if necessary
                if (column.hasSecondLayer)
               {
                        window.draw(column.secondLayerSprite);
                }

                // Draw the player if necessary
                if (column.hasPlayer)
                {
                        client->player.Draw(&window);
                }

                if (column.hasOtherPlayer)
                {
                        column.otherPlayer.Draw(&window);
                }
        }
}

Process events processed all the events and updates all the positions of the sprites with the move function
players[i].character.move(-mapOffsetX, -mapOffsetY);

In my networking it sets where and when the other player wants to move (after a few checks)
l_client->players[i].direction = d;
l_client->players[i].positionX = x;
l_client->players[i].positionY = y;
l_client->players[i].moving_request = true;


 

anything