I’m trying to write a HUD for a 2d project , I want it to basically be a translucent black rectangle w/ items on it. I can draw directly to the Graphics object and everything works but it is painfully slow. When I try to use a buffered image instead, it always comes out solid black. I’m using the hardware acceleration flags. Any Ideas? Here is the code:
/*
* HUD.java
*/
package com.krypto.k2.graphics.hud;
import com.krypto.k2.graphics.GFXEngine;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Transparency;
import java.awt.image.BufferedImage;
/**
*
* @author Krypto
*/
public class HUD
{
LifeCounter lifeCounter = new LifeCounter(5);
int x = 0;
int y = 0;
int width = 0;
int height = 0;
Color color = new Color(0.0f,0.0f,0.0f,0.5f);
BufferedImage image = null;
/** Creates a new instance of HUD */
public HUD()
{
y = GFXEngine.screenHeight-100;
height = 100;
width = GFXEngine.screenWidth;
image = GFXEngine.getGC().createCompatibleImage(width,height,Transparency.TRANSLUCENT);//new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB);
}
public void render (Graphics g)
{
Graphics2D g2 = (Graphics2D)image.getGraphics();
g2.setColor (color);
g2.fillRect (0,0,width, height);
g2.setComposite(AlphaComposite.Src);
lifeCounter.render(g2,0,20);
g.drawImage(image,x,y,null);
}
}