Sign in to follow this  

Select Pixel Transparency

This topic is 2042 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So I looked for ways to make individual pixels transparent rather than an entire window, and found this:

[CODE]
jPanel1 = new javax.swing.JPanel() {
protected void paintComponent(Graphics g) {
if (g instanceof Graphics2D) {
final int R = 240;
final int G = 240;
final int B = 240;

Paint p =
new GradientPaint(0.0f, 0.0f, new Color(R, G, B, 0),
getWidth(), getHeight(), new Color(R, G, B, 255), true);
Graphics2D g2d = (Graphics2D)g;
g2d.setPaint(p);
g2d.fillRect(0, 0, getWidth(), getHeight());
} else {
super.paintComponent(g);
}
}
}
[/CODE]

from here: [url="http://java.sun.com/developer/technicalArticles/GUI/translucent_shaped_windows/#Enabling-Per-Pixel-Translucency"]http://java.sun.com/developer/technicalArticles/GUI/translucent_shaped_windows/#Enabling-Per-Pixel-Translucency[/url]


Now the problem I have is that this is drawing the transparency directly to the JFrame. This is a problem when using this with a game, because there are serious flickering issues.

I tried double-buffering the transparency in the image I loop-draw, but it was no avail.

[CODE]
public void interpolatedDensity(int i,int j) {
//stuff
return 150<<24 | rCol<<16 | gCol<<8 | bCol;
//Partial transparency
}
public void paint() {
for (int i=0;i<800;i++) {
for (int j=0;j<800;j++) {
int c=field.interpolatedDensity(i,j);
dbPlasma.setElem(i+j*800,c); //The DataBuffer for BetterDoubleBuffer
}
}
//Stuff
g.drawImage(betterDoubleBuffer,0,0,null);
}
//Transparency ignored when painting
[/CODE]

Is there a way around this, or is there no way for a java-based (action, at least 10 FPS) game to make use of window transparency?

Share this post


Link to post
Share on other sites

This topic is 2042 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this