I'm trying to make an app in Android in which you can put different tipes of clothes on different characters.To do this i have made a square on which i put a texture (the character) with transparency (so you ca see the background, arround him) and then i added another square where the texture is the piece of clothing.The problem is that both squares with their specific textures show the backgroud, but the second square does not show the square behind him.
I guess my question is how can i make the second square show the first square and the background on the transparent parts?
make use of the Alpha component. which adds transparency to the pixel.
Look at this linkvwhich help you better
Related
I'm watching the video https://youtu.be/wIy8g8yNhNk
My first question.
As far as I understand from the video, when we draw a View that is opaque, we just put data, roughly speaking, a bitmap to the screen. That's called rendering. Is that right?
My second question.
Now let's draw a TextView with an opaque background an a semi-transparent text. Why should it be a two-step process as described in the video: we draw the TexView opaque and then apply a new alpha value to make text semi-transparent? Is it just the way Android was designed? Why can't we draw a semi-transparent pixel in one step?
My third question.
Here Ian Ne-Lewis's telling us about a view with two parts: opaque (on top) and semi-transparent (below the opaque part). He says the two parts don't overlap. But the opaque part is on top of the semi-transparent part. So why does he say these views don't overlap? As far as I understand, by "overlapping" he means having something semi-transparent on top of something opaque.
Answering your first question:
Rendering is the process executed by the Android Framework when it is drawing your opaque View on the screen.
Second Question
To render that TextView, Android will first draw the opaque background and then the semi-transparent Text. And as you saw on the video: When rendering alpha layers, android has to redraw the background layers to see what color should the alpha blend to.
That's just the way Android was designed. Even if both the background and the text were opaque, Android would first draw the background and then the text (but this time it doesn't need to check the background to blend).
Third Question
I think you didn't understand correctly the meaning of overlapping. Here's an example:
I am using LibGdx to develop a simple game for Android devices. I wish to show a progress bar using the Texture by scaling it up / down. When we do scaling the image is changing in its shape. Could you please let me know a best approach to achieve the below mentioned scenario.
Scale up is fine..
Scale down is really a problem.
If you want to do it purely by scaling, you can do one of the following
Use a mask on the green bit (use for example the blue part as a mask)
Chop the green part up in three parts: two for the round end caps and a rectangular middle piece you can scale. The problem with this is that the smalles progress you can display will be one endcap.
I want to apply the border to this custom view shape
which created by many canvas.draw...() in onDraw()
The border that i want to create and apply to my custom view should have equal range all the way with some distance from the custom view and it should also cover small circle in each slice.
Any idea how to make this?
Thanks.
This isn't so much an answer, but more of a recommendation. Take a look at the Porter-Duff modes available to you. Worst case you may need to do some per pixel image manipulation which should be fine as long as the view isn't animated.
On second thought, here's an idea: why not create two images: one large circle which will always draw behind everything and a second which will always draw behind the small circles. The large circle would just be the complete border you want displayed, whereas the small circles would actually only be a semi circle border, which would render on top of the large circle (covering the large circle border under it). The key would then be to rotate the small border circle depending on where it's located. I hippie that makes sense, but it should work and be very efficient too.
Another option would be to separate the rendering into white circles and slightly larger border color circles. If you render the slightly larger (border color) circles first, then render the normal circles (white) on top, then you won't have to worry about any rotations and it will render correctly if the small outer circles begin to overlap.
So the idea is similar to the first suggestion. You'll still need a large circle and small circle (both white), but in addition, you'll need slightly larger border colored large and small circles.
I hope this description is a little clearer, but I assume that you are comfortable enough with compound drawables to figure out the rest, given that you've gotten this far in making your view.
All the best implementing it, and feel free to ask for any clarification! :)
What I'm trying to do is have a background image, for sake of simplicity, lets say it's a picture of the front of a house. Then, I want to have a red ball move from window to window.
**I want to have a background picture, and a picture on top of it.
**I then want to be able to tell the top picture EXACTLY where to go.
How can I do this?
I'm just beginning to learn about animations in Android, and have not yet run across any way to do this.
There are two routes to animation in android: Canvas and OpenGL ES.
I would recommend OpenGL for anything requiring smoothness and speed, like a moving ball.
You should create a view using the helper class GLSurfaceView
http://android-developers.blogspot.com/2009/04/introducing-glsurfaceview.html, and implement a Renderer.
I assume you have the images saved in your res/drawable folders, in a format like png and the ball file contains an alpha channel.
You can see many tutorials online, but basically you need to load your background image and your ball resource at onSurfaceCreated and store it in a texture using GLUtils.texImage2D.
In the onDrawFrame method, you should set up a 2D projection such as glOrtho2D, then draw the background.
Then just before you draw the ball texture, you can use the glTranslate(x,y,0) function to move the ball over the house. Use an alpha blend for the ball:
glBlendFunc(GL_SRC_ALPHA, GL_SRC_ONE_MINUS_ALPHA);
glEnable(GL_BLEND);
Unfortunately writing in OpenGL isn't as straightforward as you might hope. Everything is done with 3D coordinates, despite the fact you want only a 2D image. But hopefully this gives you enough info to google for good exmaples, which are abundant!
I need to draw a bitmap on top of a completely rendered GLSurfaceView. By completely rendered I mean that the entire thing is filled with colorized triangles. Obviously the bitmap will hide the triangles underneath it, but I would like to minimize how much is hidden.
The bitmap is 64x64 pixels and has many empty areas that are translucent in the PNG file. When I draw the bitmap by making a square with two triangles, the translucent areas become black (the green areas in the picture above), perhaps because the app background is black. Is there an easy way to get the translucent areas to not affect the image (the second image above)? Do I need to create a complex set of triangles that exactly outlines the non-translucent parts when I render the bitmap?
I am developing on a Motorola Xoom, Android 3.0. Thanks for your time.
Use the alpha test.