I’m working on a game where multiple players should be able to play at a time. It’s a 2D game, and all the characters should be able to see each other move on the screen.
Like the game is now all the devices just post and fetch each others coordinates to a server. This is done by running to threads:
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();
}
Anyway, I would like the characters to move more smoothly since it can be a bit "laggy" doing it like this.Does anyone have an idea on how I can achieve this goal?
Maybe I should I have a type of coordinate stack which just gets pushed coordinates to it all the time and then pops of the values as the game runs?
Any help will be highly appreciated.
Greetings!
Check out linear interpolation / extrapolation methods to help smooth out the movement. http://en.wikipedia.org/wiki/Linear_interpolation
here are some resources on how to implement many of the numerical algorithms in practice
http://www.nr.com/
Good luck!