2020-10-31

why is drawing a bitmap on a canvas then moving it duplicating it? android, java

I'm trying to update the position of this bitmap, but it keeps duplicating it, then moving it.

private void draw() {
    if (getHolder().getSurface().isValid()) {
        canvas = getHolder().lockCanvas();

        canvas.drawBitmap(backgroundStar.starBitmap, backgroundStar.getCurX(), 
        backgroundStar.getCurY(), paint);

        getHolder().unlockCanvasAndPost(canvas);
    }
}

my update function is called after the draw,

private void update() {
    backgroundStar.setCurY(backgroundStar.getCurY() + backgroundStar.getSpeed());
}

this is the background star constructor, i left out the getters and setters

public BackgroundStar(int curX, int curY, int speed, Resources res) {
    CurX = curX;
    CurY = curY;
    this.speed = speed;

    starBitmap = BitmapFactory.decodeResource(res, R.drawable.star);
    starBitmap = Bitmap.createScaledBitmap(stareBitmap, 20,20, false);
}


from Recent Questions - Stack Overflow https://ift.tt/2JmuPzo
https://ift.tt/eA8V8J

No comments:

Post a Comment