Code example for Canvas

Methods: drawBitmap, getHeight, getWidth

0
	} 
 
	@Override 
	protected void onDraw(Canvas canvas) {
		update(canvas);
		canvas.drawBitmap(bitmap, x, y, null);
	} 
 
	public void update(Canvas canvas) {
		checkCollisions(canvas);
		x += vx;
		y += vy;
	} 
 
	public void checkCollisions(Canvas canvas) {
		if (x - vx < 0) {
			vx = Math.abs(vx);
		} else if (x + vx > canvas.getWidth() - getBitmapWidth()) {
			vx = -Math.abs(vx);
		} 
		if (y - vy < 0) {
			vy = Math.abs(vy);
		} else if (y + vy > canvas.getHeight() - getBitmapHeight()) {
			vy = -Math.abs(vy);
		} 
	} 
 
	public int getBitmapWidth() {