0
\$\begingroup\$

I am having trouble with multiplayer player movement in my game.

The client is in AS3 and the server is in C#.

Here is my problem: When I first launch the game, it connects to the server, and everything works fine. But... when I try to move my player, it isn't sending the UTF8 bytes over to the server. I even have it trace output after the socket sends the bytes. I sent the exact same bytes to the server when the game started just to see if the server recognized it, and it did.

I am not sure why it isn't even sending it at all. This is very frustrating.

private function keyDown(event:KeyboardEvent):void
    {
        switch(event.keyCode)
        {
            case Keyboard.W:
                up = true;
                break;

            case Keyboard.S:
                down = true;
                break;

            case Keyboard.A:
                left = true;
                break;

            case Keyboard.D:
                right = true;
                break;
        }
    }

    private function keyUp(event:KeyboardEvent):void
    {
        switch(event.keyCode)
        {
            case Keyboard.W:
                up = false;

                break;

            case Keyboard.S:
                down = false;
                break;

            case Keyboard.A:
                left = false;
                break;

            case Keyboard.D:
                right = false;
                break;
        }
    }

    private var playerSpdTemp:int = 5;

    private function enterFrame(e:Event):void{
        if (up){
            archer.y -= playerSpdTemp;
            socket.writeUTFBytes("move--"+archer.x+":"+archer.y);
            trace("Sent...");
        }
        if (left){
            archer.x -= playerSpdTemp;
        }
        if (down){
            archer.y += playerSpdTemp;
        }
        if (right){
            archer.x += playerSpdTemp;
        }
    }

I tried putting the socket.writeUTFBytes() in the keyDown and keyUp functions but nothing happens either...

And yes, I have the correct event listeners set up. The player moves correctly but not the socket.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Have you tried calling Socket.flush()? According to the documentation:

Flushes any accumulated data in the socket's output buffer.

On some operating systems, flush() is called automatically between execution frames, but on other operating systems, such as Windows, the data is never sent unless you call flush() explicitly. To ensure your application behaves reliably across all operating systems, it is a good practice to call the flush() method after writing each message (or related group of data) to the socket.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .