Overlay Example

Started by Polomease, January 23, 2011, 09:57:18 AM

Previous topic - Next topic

Polomease

Is there an example of how to use the Overlay class anywhere?
I've done a lot of searching and can't find one.

I've been trying to get it to work and I just can't seem to figure it out.

From the java docs it sounds like you can just create an instance of the class and it should take care of itself from there.

Below is a snippet of what I am trying to do in the onSurfaceChanged() event.

        private Overlay MapFrame = null;

        @Override
public void onSurfaceChanged(GL10 gl, int w, int h) {

              fb = new FrameBuffer(gl, w, h);
      world = new World();
      world.setAmbientLight(200, 200, 200);
              /* the rest of the initialization code left out for brevity, it just loads a bunch of objects and textures*/

              //"minimapframe" is a known texture in the texture manager
              MapFrame = new Overlay(world, 0, 0, 128, 128, "minimapframe");

              // I've been trying different combinations of this code
              //MapFrame = new Overlay(world, fb, "minimapframe");
              //MapFrame .setSourceCoordinates(0, 0, objTextureManager.getTexture("minimapframe").getWidth(), objTextureManager.getTexture("minimapframe").getHeight());
              //MapFrame .setVisibility(true);
              //MapFrame .setDepth(10.0F); // have tried different values here

         }


From my understanding this should display the "minimapframe" texture in the upper left of the screen.

I am missing something?


EgonOlsen

#1
It was a straight port from the desktop version and to be honest, i never tried it on Android. But i did now and i can confirm, that it doesn't work. I'm not sure why...i'll look into it later. However, have you considered to use blitting instead? That's what most (...all?) users do, which is why none has ever noticed that Overlay doesn't work on Android.

EgonOlsen


Polomease


Sweet!  :D
The new version works like a charm.
Thank you Egon for the quick response and fix.

One other thing about Overlays, it seems that they are not selectable in AE.
I noticed that the desktop version has a method setSelectable() but the AE version does not have this.
Is this functionality available in the AE version?
If not, that's ok, I can just do a simple 2D coordinate check, I was just curious.




shalafi

Thanks for the info, I was having the exact same problem and the new library worked straight away.

AFAIK the latest version on the web still has this problem.

shalafi

Now, something strange.

If I use this library, which makes Overlays work, animations are messed up.

I have an object in which I set an animation. With the previous version of the library it was displayed fine. With this version it does not display until I modify the animation.

This should not be a problem if I could set the animation to a default frame when adding the object to the world, but that does not work.

If I don't set the animation, it renders properly.

Any idea of what can I do to solve this or why is it happening?

EgonOlsen

I'm not aware of any animation related changes in that version. Do you have a test case?

shalafi

I was writing this when you answered.

Just to be clear, I want an object on screen that when you click something starts animating.

What I have found so far is

if I do:

world.addObject(object);
object.build();

The object is displayed fine without animation (animation is not set)

If I do:

world.addObject(object);
object.setAnimationSequence(animation);
object.animate(0);
object.build();

The object is not displayed until the animation starts. This worked fine with the version of the library that does not have the Overlays patch.

If I do:

world.addObject(object);
object.build();
object.setAnimationSequence(animation);
object.animate(0);

The object is displayed but the animation does not work:

shalafi

Oh, and animation is loaded like this:

Object3D [] animationFrames = Loader.load3DS(res.openRawResource(R.raw.animation), 1);

for (int i=0; i<animationFrames.length; i++) {
animationFrames[i].build();
}
animation = new Animation(animationFrames.length);
animation.createSubSequence("animation_1");
for (int i=1; i<animationFrames.length; i+=5) {
animation.addKeyFrame(animationFrames[i].getMesh());
}
animation.setClampingMode(Animation.USE_WRAPPING);
animation.setInterpolationMethod(Animation.LINEAR);

EgonOlsen

The last code snippet can't work, because when calling build() before assigning the animation, the object will be compiled for static mode.
In the second snippet, calling animate(0) before calling build() is also questionable. Have you tried to swap those calls?

shalafi

#10
Quote from: EgonOlsen on May 18, 2011, 11:26:45 AM
The last code snippet can't work, because when calling build() before assigning the animation, the object will be compiled for static mode.
In the second snippet, calling animate(0) before calling build() is also questionable. Have you tried to swap those calls?

I was just pointing that I tried several combinations, I know calling build() before assigning the animation should not work, and that's what it does.

Edit:

if I swap animate & build It actually works,

I was sure I had tried all possible combinations, thanks!

The strange thing is, it works with the other version of the library.