我正在开发一个游戏,其中多个玩家应该能够同时进行游戏。这是一款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();
}无论如何,我希望角色移动得更流畅,因为它可以像this.Does一样做得有点"laggy"。有人知道我如何实现这个目标吗?
也许我应该有一种坐标堆栈,它只是一直将坐标推送到它,然后在游戏运行时弹出值?
任何帮助都将受到高度的感谢。
欢迎光临!
发布于 2012-03-29 18:28:49
检查线性插值/外推方法,以帮助平滑移动。http://en.wikipedia.org/wiki/Linear_interpolation
这里有一些关于如何在http://www.nr.com/实践中实现许多数值算法的资源
祝好运!
发布于 2012-03-29 18:32:45
我知道这是flash,但这是一个很好的教程来改进玩家的移动:http://playerio.com/documentation/tutorials/building-flash-multiplayer-games-tutorial/
https://stackoverflow.com/questions/9923450
复制相似问题