views:

150

answers:

1

This question may have been asked before, but I'm starting to get into game programming on the Android. I'm having a hard time figuring out the best way to move an object.

To put it simply, lets say I have a bitmap located on 0,0 and i want to move it across the screen. The obvious way to do it would be to simply increment the X position by one every time the Surface View onDraw method gets called.

But what if I wanted to make it move faster? I could increment it by two or three instead of one, but then the movement starts to get really choppy and stupid looking.

What is the best way to go about doing this?

+3  A: 

Learn a bit about vectors. http://chortle.ccsu.edu/VectorLessons/vectorIndex.html

Movement is usually calculated by adding a vector scaled by a time delta to the current position. (Math talk makes simple things so complicated).

Basically: new_Pos = old_Pos + mov_Vec * time_delta

So by changing the mov_Vec you can increase/decrease speed.

You can also do it on x,y new_x = old_x + mov_x * time_delta

Some sites to check out

http://gpwiki.org/

http://www.gamedev.net/

http://www.devmaster.net/

HyperCas