What's the best way to move object

I’ve been thinking that which way is the best to move something to some direction in some time.

Let’s say that I have Thread that sleeps 100 ms and I move image to right with x+=1. I can make image move as much in same time to right so that I put thread to sleep 200 ms and move Image x+=2. Which way is better (or is there a better way at all)?

If you mean a separate thread… then no. Don’t do that.

Move everything in the main thread. Moving things more often (and in smaller steps) will look smoother. Try to aim for the de facto standard of 60 fps.

Thank you for answering!

Ok. Why everything should be in main thread? I have nothing against that but I am just curious. Is it because then repainting and moving would be synchronied?

Yes, it’s synchronous and there is also little overhead. In some games you have 2000 or even more objects. Using a thread for each would slow it down to a crawl. Parallelizing things on such a low level simply doesn’t work with most languages. Or let me put it this way: it doesn’t work with threads.

Erlang for example is able to parallelize even the tiniest tasks, but Java or C/C++ use a different architecture. Threads are pretty heavyweight and should be only used for rather big tasks.

Multitreading isn’t required or even remotely sensible for most small-scale games. It’s a source of really nasty errors and there is very little to gain. It’s good for speeding up the loading process (if you know what you’re doing) or making the loading screen smooth though.

Thanks for your information!

I recommend learning how to use a time lapse variable in your main loop, like tau. I actually have a write-up I made for it, which I can post for you. Note that this comes from a technical report on the process of making my game Agent: 00PK, and is meant for the layman. As such, some of this might be completely obvious.

Basically what you do is make your thread yield when it’s going too fast, ( Thread.yield() ), and move everything a certain amount times tau each timestep. The bigger tau is (the longer the wait), the more you move each object. The opposite is naturally also true.

Thank’s for your help!

I have to read that text few times now. Due to my average english skill I have to focus to everything that I read and it takes time to understand everything.

Sure. If you’ve got questions, I can help as well. Just post them here.