jPCT-AE - a 3d engine for Android > Support

Overlapping overlays, using transparency...help!?

(1/3) > >>

mbowen89:
Ok, so I have tried to read up on everything I could do with this, and tried a lot of stuff but can't seem to nail this... please help.

Basically I want to create some gauges as a HUD, so for example an RPM gauge.

I made it in GIMP as a 128x128 square for example, with transparent background. I made the round gauge centered, and I also made a needle centered on transparent background, check these two images out:

Gauge:
Needle:

So if I make two overlays, both at 0,0... they overlap perfectly, I can rotate the needle overlap to correlate with RPM, awesome. BUT, I get a black background of a square instead of transparency... ok so I do rpm_gauge.setTransparency(100); for example, and the black goes away and is transparent. I do the same for needle. BUT when I set the transparency on the main gauge, the needle also disappears with it. Here is the code that does that:


--- Code: ---                                TextureManager.getInstance().addTexture("rpm_gauge", new Texture(getResources().openRawResource(R.raw.rpm_gauge_128), true));
rpm_gauge = new Overlay(world, 0, 0, 128, 128, "rpm_gauge");
rpm_gauge.setDepth(1.1f);
rpm_gauge.setTransparency(255);
TextureManager.getInstance().addTexture("rpm_gauge_needle", new Texture(getResources().openRawResource(R.raw.rpm_gauge_needle_128), true));
rpm_gauge_needle = new Overlay(world, 0, 0, 128, 128, "rpm_gauge_needle");
rpm_gauge_needle.setDepth(1f);
rpm_gauge_needle.setTransparency(255);

--- End code ---

If I comment out: rpm_gauge.setTransparency(255);, the needle reappears but the gauge has black for transparent areas. I've tried using different transparency values for both, changed depth, etc... am I doing something wrong?

Thanks

---------
Edit:

Ok, so I reversed the order in which I create the overlays (needle first), and of course it works now... somewhat. The needle likes to flicker quite a bit, and disappeared one time as well until I made it rotate by increasing RPM again. I'm actually doing this with a boost and speed gauge as well. Hopefully I can get a better working solution? Thanks :)

EgonOlsen:
You can set the depth of an overlay. Try to set the gauge's depth to something like 1.5.

mbowen89:
This code makes the gauge transparent (good) but makes the needle disappear:

--- Code: ---                                TextureManager.getInstance().addTexture("rpm_gauge", new Texture(getResources().openRawResource(R.raw.rpm_gauge_128), true));
rpm_gauge = new Overlay(world, 0, 0, 128, 128, "rpm_gauge");
rpm_gauge.setDepth(1.5f);
rpm_gauge.setTransparency(255);
TextureManager.getInstance().addTexture("rpm_gauge_needle", new Texture(getResources().openRawResource(R.raw.rpm_gauge_needle_128), true));
rpm_gauge_needle = new Overlay(world, 0, 0, 128, 128, "rpm_gauge_needle");
rpm_gauge_needle.setDepth(1f);
rpm_gauge_needle.setTransparency(255);

--- End code ---

This code makes the needle appear, but it flickers as vehicle and camera move down track:


--- Code: --- TextureManager.getInstance().addTexture("rpm_gauge_needle", new Texture(getResources().openRawResource(R.raw.rpm_gauge_needle_128), true));
rpm_gauge_needle = new Overlay(world, 0, 0, 128, 128, "rpm_gauge_needle");
rpm_gauge_needle.setDepth(1f);
rpm_gauge_needle.setTransparency(255);
TextureManager.getInstance().addTexture("rpm_gauge", new Texture(getResources().openRawResource(R.raw.rpm_gauge_128), true));
rpm_gauge = new Overlay(world, 0, 0, 128, 128, "rpm_gauge");
rpm_gauge.setDepth(1.5f);
rpm_gauge.setTransparency(255);

--- End code ---

EgonOlsen:
Try some other depth....maybe 2, 5 or 10 instead of 1.5

mbowen89:
I added some other overlays with transparency, and they work great since I'm not trying to overlap them, however they still like to flicker. I changed their depth to 2 and that seemed to help them, though the needle still flickered.

Is this actually moving them 2 units from camera? I don't know the right terminology. What if the camera get within 2 units of something?

Edit: Made gauge depth 3, needle depth 2 and no more flicker. Sweet!

Still confused why overlay creation order trumps depth... :(

When I put the camera into the driver seat position, the overlays go partially behind part of the object frame... that's why I hate that I have to move them out so far :(

Any idea?

Navigation

[0] Message Index

[#] Next page

Go to full version