views:

56

answers:

2

What algorithm or technique should I use to make an object follow the path that the user's drawing on the screen?

+3  A: 

The below example creates a PATH for displying TEXT on Circle Path:

// create a path Path circle = new Path(); circle.addCircle(centerX, centerY, radius, Direction.CW);

// set the color and font size
Paint paint = new Paint();
paint.setColor(Color.BLUE);
paint.setTextSize(30);
paint.setAntiAlias(true);

// draw the text along the circle
canvas.drawTextOnPath(QUOTE, circle, 0, 30, paint);

You can refer full Example Here

And For Animation, There are mainly 4 Types of Animations comes up with Android SDK:

  1. AlphaAnimation – transparency changes
  2. RotateAnimation – rotations
  3. ScaleAnimation – growing or shrinking
  4. TranslateAnimation – position changes

For CREATING ANIMATION SEQUENCES, refer Example Here.

For Different Types of Animations Example such as Frame Animation (As in Flash), List Animation,etc. You can refer Animations Types EXample here .

Enjoy!!

PM - Paresh Mayani
can I use this on SurfaceView and instead of Circle I can change to complex path?
SteveThai
A: 

I was just working on this in the last couple weeks for a game--how I did it was by getting each point from coordinates given by the touch event (when the user is drawing it to the screen) and then adding that to a list. I turned that list into a path to draw to the screen, and then just had the object update its location based on the list in the onDraw method for each frame.

mportiz08