Libgdx, sprite batch and setColor to specific region - libgdx

So I have a simple texture: one big green circle in the center and one small white circle also in the center of my texture. And now I want to change color of my white circle to yellow in my app. Is it possible and what is the best way to set color of my batch for specific region? I saw it is possible in other engines using the second texture with marked region which color will be changed.
Like that:
http://s9.postimg.org/qh7bbu5an/FINAL.png
My original texture
2nd texture with region which color i want to change
The result of my texture in app which will be working like batch.setcolor but only for specific region (pixels) in my texture

If you are looking for an example of masking textures together, you can check this tutorial.
https://github.com/mattdesl/lwjgl-basics/wiki/ShaderLesson4
It also has a port to libGDX.

Related

Libgdx: Remove white space in a sprite

I recently started using Libgdx for the first time and I'm trying to make a 2D game similar to Zelda/Pokemon.
The problem I'm having is that I don't know how to make the sprite blend with the background (a tiled map .tmx file). I tried using enableBlending() but it doesn't work. I want the white space around the sprite to be removed so that the tiled map background shows.
tiled map with the sprite
Thanks
Blending is not required in your case.
Just use .png(having transparent background) file instead of .jpg(having white background).

AS3 Bitmap black and white - for compression reasons

I have a field made up of BitmapData, which I use for pixel-precise hit detection.
However, BitmapData naturally stores 2^32 (or 2^24 with no alpha?) possibilities for each pixel. I only need 2 - black or white.
But I still need to use .draw to make other objects being drawn onto that BitmapData. It doesn't need to be visible.
Extracting a pixel for hit-detection does not seem too difficult - but drawing without cycling through each pixel seems hard. Is it possible?
What would the right approach for this problem be?
If you depend on having your bitmap data to be black or white only, you can employ BitmapData.threshold() after drawing a new mask over that bitmap. To turn your existing BitmapData to black and white with a threshold of half red channel do the following:
bd.threshold(bd,bd.rect,new Point(),"<",0x00800000,0x0,0x00ff0000,true);
bd.threshold(bd,bd.rect,new Point(),">=",0x00800000,0x00ffffff,0x00ff0000,true);
The first call with turn all points that have red below 0x80 black, the second will turn all the remaining points white. Change the mask and threshold value to use green or blue channels if you want. Consider applying a properly channeled ColorTransform object to your draw calls to make the mask correctly applied to a newly drawn object.

Drawing the exact region of the Bitmap in as3

I am working on a Action Script 3.0 application , in which i ill be allowed to load the image and make them draggable. Consider i am loading the deer image and making it as draggable.
Problem with this is , if i click on the translucent area ( white space around the bitmap ), i dont want the bitmap to draggable.is there any way to draw the deer boundary region exactly without the white space around it.
You can use BitmapData methods to get each pixel color, and then, you can either :
On creation, for each pixel if it's not fully transparent (!= 0) you can draw a point of a Shape, which will be transparent, and make it dragable in place of your bitmap (as noticed in comment, it will be quite CPU consuming, so use the second method)
On click, get the click coordinate relative to the bitmap, check if the pixel is transparent and make it drag only if it's not.
In either way, that will be quite CPU consuming. You may also consider convert your bitmap to a vector image (Sprite). This will allow flash to detect real images boundaries.

how to load image dynamically in Flash actionscript3?

I want to load the image dynamically in Flash actionscript, like this :
When the user select the image it should contain inside the frame instead of black plane box. I am thinking If I can apply that image as background image for that black plane box (which I draw separately inside the frame) that would be great. Because over here the issue is the image should look like 3D inside the frame, so maybe the background or texture method will solve this problem. Please friends give me suggestion...
Thanks.

BitmapData.draw with different shape

is it possible to change the Rectangle I use as fifth parameter of draw BitmapData class?
bitmapData.draw(image,null,null,null,rect,false);
I'm trying to draw and save a different shape (with the shape of a particular MovieClip).
If you look at the definition for the BitmapData's copyPixels method (adobe documentation), you'll see:
"If you include the alphaBitmap and alphaPoint parameters, you can use
a secondary image as an alpha source for the source image. If the
source image has alpha data, both sets of alpha data are used to
composite pixels from the source image to the destination image. The
alphaPoint parameter is the point in the alpha image that corresponds
to the upper-left corner of the source rectangle. Any pixels outside
the intersection of the source image and alpha image are not copied to
the destination image."
You can probably get this to do what you want.