开发者

move an object follow a user-defined path on Android

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


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!!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜