簡體   English   中英

在不斷增長的Arc內部繪制位圖

[英]Draw bitmap inside of growing Arc

我有1個問題和1個問題。

我想要在游戲中繪制一個擴展的弧,到目前為止,我已經設法使其逐漸擴展,但是在某個點之后,弧停止擴展並消失了,那是為什么呢?

這是我的弧代碼:

public void render(Canvas canvas) {
    if(gameState == TESTMODE){
        drawMainBg(canvas);
        hModeRadius += 50*thread.getDelta();
        Paint p = new Paint();
        RectF rectF = new RectF(hModeY - hModeRadius, hModeX + hModeRadius, hModeX + hModeRadius,  hModeY-hModeRadius);
        p.setColor(Color.WHITE);
        canvas.drawArc (rectF, 0, 360, true, p);
    }

現在,我的第二個也是主要的問題是,有沒有辦法用位圖填充這個弧度? 我想使用此弧線更改游戲中的背景,並想將背景擴展為弧線,直到它填滿屏幕為止。

您可以為此使用BitmapShader

// Define a method to generate a bitmap shader from a drawable resource
private static Shader getDrawableShader(Context ctx, int resId) {
    Bitmap bmp = BitmapFactory.decodeResource(ctx.getResources(), resId);
    return new BitmapShader(bmp, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
}

// Outside of onDraw(), preferably on a background thread if possible
Shader shader = getDrawableShader(getContext(), R.drawable.my_image);

// In onDraw()
paint.setShader(shader);
canvas.drawArc(rectF, 0, 360, true, paint);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM