Reputation: 1636
I am making a 2D game for the Android platform. The character is supposed to move only up and down, so I want to create 2 arrows for movement at the bottom of the screen so the player can move the character up and down. I also want to make sure that they are not blocking the view or that the player can't see what he is doing, so I want them to be about 50% transparent.
How can I control the Bitmap's transparency level? I am using canvas on a SurfaceView
and I control it in a thread using lockCanvas
and unlockAndPost
.
Upvotes: 1
Views: 385
Reputation: 98521
When you draw the bitmap, you pass a Paint as an argument. You can set the transparency level on the Paint by using Paint.setAlpha():
paint.setAlpha(127); //50% translucent
canvas.drawBitmap(bitmap, x, y, paint)
Upvotes: 2