views:

64

answers:

1

I have no working code at all, but I'll post my method of display the image I need to bobble.

public void onDraw(Canvas can){

can.drawBitmap(bobbleHead , xpos, ypos, p);

}

I have xpos and ypos declared.

A: 

If all you want is for the head to move up and down, you need to use a sin function to modify ypos. For example, if you want the head to bob up and down once a second, you can calculate ypos using the time in seconds:

time = now - start;
ypos = ypos_at_rest + ypos_extension * sin(time * pi * 2.0);

Forgive me if the syntax is a little off, I'm extrapolating Java from C.

Mark Ransom
I'll try it in a moment.
Aaron
I'm having a really hard time getting this concept ported into android java...here's where I am at so far...double d = (int) (time * Math.PI * 2.0);ypos = (int) (50 + 15 * Math.sin(d));can.drawBitmap(bobbleHead , xpos-(xpos/2), ypos, p);time keeps getting and error...I'll keep trying different techniques. Appreciate the direction!
Aaron