does anyone know how i can make my image move smoothly?
here is a snippet of my code:
@Override
public void onDraw(Canvas canvas) {
Bitmap _scratch = BitmapFactory.decodeResource(getResources(),R.drawable.terrain);
canvas.drawColor(Color.BLACK);
canvas.drawBitmap(_scratch, _x, _y, null);
_y-=10;
}
its been based off the lunar lander tutorial.
what it does is stutter, it does on both my emulator, and my phone.
i have tried moving it by one, but it doesnt execute fast enough to give me the motion i want.
sorry if this isnt formated correctly, the editor was playing up.
decodeResourceis a hugely expensive call. You shouldn’t do it so often, and especially not in this method. Decode it earlier and store the result as a field, which you would then use in theonDraw(..)call.