Piszę grę RPG. Moim celem jest, żeby po wejściu na określone pole w grze sprite (chibi1) został stopniowo zmniejszony o określoną wartość. Lecz obecnie nie wiedzieć czemu nie dość, że się nie zmniejsza to jeszcze aplikacja zaczyna strasznie lagować. Oto kluczowe fragmenty kodu:
public class Gra extends Activity {
(...)
public void chibiMovedIntoTeleport() {
Bitmap defaultChibiBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.chibi1);
Runnable runnable = new Runnable() {
public void run() {
for(int i=0; i<40; i++) {
chibiBitmap = Bitmap.createScaledBitmap(defaultChibiBitmap, gs.defaultChibiWidth-i,gs.defaultChibiHeight-i, false);
gs.chibi1.image = chibiBitmap;
handlerReduceSizeOfChibi.postDelayed(this, 1000);
}
}
};
runnable.run();
}
}
ta metoda jest wywoływana na onDraw klasy rozszerzającej SurfaceView
public class GameSurface extends SurfaceView implements SurfaceHolder.Callback {
@Override
public void draw(Canvas canvas) {
super.draw(canvas);
if(chibiNode==17)
((Gra)getContext()).onChibiMovedIntoTeleport();
(...)
}
(...)
}
public class ChibiCharacter extends MovingObject {
(...)
}
public abstract class MovingObject {
private static final int ROW_TOP_TO_BOTTOM = 0;
private static final int ROW_RIGHT_TO_LEFT = 1;
private static final int ROW_LEFT_TO_RIGHT = 2;
private static final int ROW_BOTTOM_TO_TOP = 3;
private Bitmap[] leftToRights;
private Bitmap[] rightToLefts;
private Bitmap[] topToBottoms;
private Bitmap[] bottomToTops;
public boolean justSeen=true;
public Bitmap image;
private final int rowCount, colCount;
public int WIDTH;
protected int HEIGHT;
private int width, height;
private int rowUsing = ROW_LEFT_TO_RIGHT;
private int colUsing;
// Velocity of game character (pixel/millisecond)
public float velocity = 0.15f;
public int movingVectorX = 0;
public int movingVectorY = 0;
public long lastDrawNanoTime =-1;
public GameSurface gs;
private int x;
public MovingObject(GameSurface gs, Bitmap image, int rowCount, int colCount, int x, int y) {
this.gs = gs;
this.image = image;
this.rowCount = rowCount;
this.colCount = colCount;
this.x = x;
this.y = y;
this.WIDTH = image.getWidth();
this.HEIGHT = image.getHeight();
this.width = this.WIDTH / colCount;
this.height = this.HEIGHT / rowCount;
this.topToBottoms = new Bitmap[colCount];
this.rightToLefts = new Bitmap[colCount];
this.leftToRights = new Bitmap[colCount];
this.bottomToTops = new Bitmap[colCount];
for(int col = 0; col< this.colCount; col++ ) {
this.topToBottoms[col] = this.createSubImageAt(ROW_TOP_TO_BOTTOM, col);
this.rightToLefts[col] = this.createSubImageAt(ROW_RIGHT_TO_LEFT, col);
this.leftToRights[col] = this.createSubImageAt(ROW_LEFT_TO_RIGHT, col);
this.bottomToTops[col] = this.createSubImageAt(ROW_BOTTOM_TO_TOP, col);
}
}
public Bitmap[] getMoveBitmaps() {
switch (rowUsing) {
case ROW_BOTTOM_TO_TOP:
return this.bottomToTops;
case ROW_LEFT_TO_RIGHT:
return this.leftToRights;
case ROW_RIGHT_TO_LEFT:
return this.rightToLefts;
case ROW_TOP_TO_BOTTOM:
return this.topToBottoms;
default:
return null;
}
}
public Bitmap getCurrentMoveBitmap() {
Bitmap[] bitmaps = this.getMoveBitmaps();
return bitmaps[this.colUsing];
}
public void draw(Canvas canvas) {
Bitmap bitmap = this.getCurrentMoveBitmap();
canvas.drawBitmap(bitmap,x, y, null);
// Last draw time.
this.lastDrawNanoTime= System.nanoTime();
}
protected Bitmap createSubImageAt(int row, int col) {
// createBitmap(bitmap, x, y, width, height).
return Bitmap.createBitmap(image, col * width, row * height, width, height);
}
(...)
}
Pytanie: DLACZEGO TEN SPRITE SIĘ NIE ZMNIEJSZA?!
Pozdrawiam cieplutko.