I've used GIMP to create a sprite using a transparent background. Once I put it in the Image Packer the transparent background disappears and the whole image is messed up. After a bit of googling without finding a single useful thing I decided to use a pink background, but I can't find support for setting a pixel to alpha (I can read the pixel's color though!)
How do I fix this and have a transparent background in my sprite (org.newdawn.slick.Image to be precise)?
Useful links: None as far as I can remember. Took me 45 minutes to jump to this site for help, so there's either pretty much nothing or literally no support.
Are you sure the image is saved in a format that supports the transparency? For example JPG does NOT support transparency. PNG does.
Also are you sure that when saving the picture the background is indeed transparent and not white? To double check the background is transparent the majority of image editors will display a grey and white checked grids to show transparency.
Related
I am using the LibGDX orthographic camera class to handle different screen sizes and it works pretty well for me. The only issue I have is the border around the screen when the device doesn't stretch to scale.
I don't mind a border that much, the only thing that bothers me is the color of the border. I think it would look much nicer if it was black instead of white. Any way to change that?
Also I posted another question about android touch handling that was never answered. If someone could answer that, that would be great. I don't want to have to ask it again, I don't want to seem spammy. My Question
When your camera view is smaller than screen you probably just need to change clear color of GL.
glClearColor(r, g, b, a);
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0,0,0,1);
Black clear screen. Thats all you need.
I'm using SVG files in my Game and i want to add transparency and brightness effects to them. So what i want is that a sprite becomes more and more transparent until it's invisible. This looks much smoother than a just disappearing sprite. This allows also smooth transitions between the levels where a white screen gets less transparent and then again more. I hope you understand what i mean. Besides this a brightness effect would be nice, too. A sprite can get brighter or darker during the game. Nevertheless i could create a workaround for this using the transparency effect, but yeah, i have none :/
I use this library:
https://androidsvg.googlecode.com/hg/doc/reference/packages.html
I render my svgs on this way:
svg.renderToCanvas(pCanvas);
However i can also convert it to pictures:
Picture pic = svg.renderToPicture();
Maybe this information will help you.
Does there exist something what could help me? And if not, have you an idea how can i solve the problem?
EDIT:So iwant my SVGs behave like these ones:
http://scratch.mit.edu/projects/24634091/
You could use an ImageView and setAlpha(), as Frank says. Or it may just be easier to render the sprites to the canvas in your draw() method.
If you are writing a game, then you may find that rendering SVGs in your game loop may not be fast enough. So you might have to pre-render all your SVG sprites to Bitmaps (ie on startup) and draw them to your Canvas.
Paint p = new Paint();
p.setAlpha(alpha);
canvas.drawBitmap(sprite, x,y, p);
I am currently working on making a Java videogame with a few friends. It is a top-down RPG that is drawn with tiles of different types. I just added a day/night cycle to the game, and found that using transparent colors to draw to the screen is very slow. I recently learned how to make colors transparent by adding an alpha-value after the RGB values, and it works very well, but as I said, it is slow. I tried switching between transparent colors and opaque colors and discovered that the lag is because of the transparency. Basically, after a tile is drawn, it calls the method for getting the desired transparency factor, makes a new color, and calls g.fillRect() over the tile. This is done for every tile on screen.
I would like to know if there is another way to have a transparent overlay without just drawing the overlay over the whole window, because we want to be able to add light sources that replace the transparency for specific tiles. The tiles are drawn to the screen from a spritesheet. Any suggestions are welcomed.
Preferably, I'd like a somewhat fancy bevel . I'd like the picture to have some depth on it..so it doesn't look so plain and old-fashion :)
You can perhaps do something with the 2D Canvas API, but I don't know enough about that to describe a process. Here's how you can try to do that with ordinary widgets...well, mostly ordinary...:
Step #1: Create a nine-patch PNG that has your "somewhat fancy bevel" and is designed to stretch around images.
Step #2: Set that nine-patch PNG as the background of the ImageView that has your image.
Step #3: Adjust the padding of the ImageView so that your bevel shows -- that'll depend on how wide you made the bevel effect.
It's possible you'll need to put the nine-patch PNG on a LinearLayout or something and have the ImageView in there (then use margins to allow the bevel to peek through), but I think you can do it without the extra widget.
I would say that the easiest thing to do is to set nine-patch PNG as the background of your ImageView. This way the src would load the image, while background attribute would load the background 9.png image.
When creating 9.png for the background take care that you do not mark border lines as streatchable. Look at the image.
I'm trying to use a transparent PNG as the icon for my Java application. The image on the JFrame and task bar work great. However, when I use the image with a TrayIcon, I get a black matte background around the edge of the PNG.
Has anybody else come across this issue? I would really like to use a PNG instead of GIF or JPEG.
With Java6, a PNG picture should be used for TrayIcon, but as mentioned in this SO question, check:
the background color chosen to represent the transparent pixels
the transparency options
the resolution of the icon
alternate format like SVG (provided you are using external library like Batik, and conversion mechnism to java.awt.Image)