First of all, try change
private final Handler handlerReduceSizeOfChibi = new Handler();
to
private final Handler handlerReduceSizeOfChibi = new Handler(Looper.getMainLooper());
Second, the way you using handler was wrong. That handler basically will call your Runnable
every ~1 second for 5 times and that causes infinite loop
.
This is probably what you wanted.
public void reduceSizeOfChibi() {
int defaultChibiWidth = chibi1.getWidth();
int defaultChibiHeight = chibi1.getHeight();
int chibiXWhenCall = chibi1.getX();
int chibiYWhenCall = chibi1.getY();
Bitmap defaultChibiBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.chibi1);
for(int i=0; i<50; i+=10) {
handlerReduceSizeOfChibi.postDelayed(new Runnable() {
public void run() {
chibiBitmap = Bitmap.createScaledBitmap(defaultChibiBitmap, defaultChibiWidth - i, defaultChibiHeight, false);
chibi1 = new ChibiCharacter(GameSurface.this, chibiBitmap, chibiXWhenCall, chibiYWhenCall);
GameSurface.this.invalidate(); //Update ChibiCharacter every 1 second.
}
}, 1000);
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…