的想法是有性格和其蹤跡獨立計算編程有些時候,你只需撥打
add_point_to_path (mPosX, mPosY);
它會將當前的精靈位置添加到路徑中。
更改mPathPaint,您可以自定義路徑種類,如您所知。此外,您還可以添加圓弧,曲線等..
更好的解決方案
另一種解決方案是創建一個位圖,透明的,下面的一切:
public void onDraw(Canvas canvas) {
// we draw our auxiliary bitmap that contains all the trails
canvas.drawBitmap (mTransparentBitmapForTrails, 0, 0, mTransparentBitmapPaint);
.
// then we draw the usual stuff, characters, etc...
canvas.drawBitmap (mCharacterBimap, mPosX, mPosY, mCharacterPaint);
.
.
}
// this creates a transparent background the size of the screen
// you will render trails here and they all will be painted at once in onDraw below the craracters
Bitmap mBitmapForTrails;
Canvas mCanvasForTrails;
public void initializeBitmapForTrails() {
mBitmapForTrails=new Bitmap(); // checkout how to create bitmaps with specific w&h, can't remember at the moment.
mCanvasForTrails=new Canvas(mBitmapForTrails); // we create a canvas to draw in that bitmap
}
// this will paint the trail in our secondary bitmap. This secondary bitmap doesn't get
// erased, so the drawTrail()'s are accumulative
public void drawTrail (int x, int y) {
mCanvasForTrails.drawBitmap(your_cool_trail_bitmap, x, y, mTrailPaint);
invalidate(); // this works, but for performance you'll later do invalidate(rect), so Android only repaints the changed portion of the bitmap. That rect will be the rectangle occupied by the trail bitmap. ie. (x,y,x+trailw,y+trialh)
}
所以你會畫畫所有該位圖的路徑。這具有的優點是路徑可能非常複雜而根本不影響性能。
追蹤將會是另一個精靈 – rupps
是的,追蹤將是另一個精靈。目前,我已經將該精靈轉換爲位圖並被繪製出來,但它並不像它應該的那樣運行。 – user3471603
你應該像人物一樣畫它,有什麼問題? – rupps