【发布时间】:2012-03-29 10:20:41
【问题描述】:
我正在开发一款应该可以同时让多个玩家玩的游戏。这是一个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();
}
无论如何,我希望角色移动更顺畅,因为这样做可能有点像"laggy"。有人知道我如何实现这个目标吗?
也许我应该有一种坐标堆栈,它总是将坐标推送到它,然后在游戏运行时弹出值?
我们将不胜感激。
您好!
【问题讨论】:
标签: android network-programming multiplayer