多人游戏编程

Ara*_*raw 5 android network-programming multiplayer

我正在制作一个多个玩家应该能够一次玩的游戏.这是一个2D游戏,所有角色应该能够看到对方在屏幕上移动.就像游戏一样,现在所有的设备都只是发布并将其他人提取coordinates到服务器.这是通过运行到线程来完成的:

public void StartCoordinatorFetcherThread(final Sprite Object)
{
    Thread CoordinateStarter = new Thread()
    {
        public void run()
        {           
            while(true)
            {
                Object.testing = Object.InternetObject.GetMessages();
                try {
                    Thread.sleep(20);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    };
    CoordinateStarter.start();
}

public void StartCoordinatorPosterThread(final Sprite Object)
{
    Thread CoordinatePoster = new Thread()
    {
        public void run()
        {           
            while(true)
            {
                Object.InternetObject.PostCoordinates(Object.x,Object.y);
                try {
                    Thread.sleep(20);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    };
    CoordinatePoster.start();
}
Run Code Online (Sandbox Code Playgroud)

无论如何,我希望角色能够更顺利地移动,因为它可以"laggy"像这样做.有人知道如何实现这个目标吗?

也许我应该有一种坐标堆栈,它只是一直推动坐标,然后在游戏运行时弹出值?

任何帮助将受到高度赞赏.

问候!

Mar*_*bar 2

查看线性插值/外推方法以帮助平滑运动。http://en.wikipedia.org/wiki/Linear_interpolation

这里有一些关于如何在实践中实现许多数值算法的资源 http://www.nr.com/

祝你好运!