Author Topic: Overlay Example  (Read 7841 times)

Offline Polomease

  • byte
  • *
  • Posts: 9
    • View Profile
Overlay Example
« on: January 23, 2011, 09:57:18 am »
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.
Code: [Select]
        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?


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Overlay Example
« Reply #1 on: January 23, 2011, 10:42:23 am »
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.
« Last Edit: January 23, 2011, 12:42:04 pm by EgonOlsen »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Overlay Example
« Reply #2 on: January 23, 2011, 12:41:26 pm »
Should be fixed now. Please give this version a try: http://www.jpct.net/jpct-ae/download/tmp/test/jpct_ae.jar

Offline Polomease

  • byte
  • *
  • Posts: 9
    • View Profile
Re: Overlay Example
« Reply #3 on: January 23, 2011, 11:57:43 pm »

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.




Offline shalafi

  • byte
  • *
  • Posts: 21
    • View Profile
Re: Overlay Example
« Reply #4 on: May 11, 2011, 01:51:26 pm »
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.

Offline shalafi

  • byte
  • *
  • Posts: 21
    • View Profile
Animations Vs Overlays
« Reply #5 on: May 18, 2011, 10:07:43 am »
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Overlay Example
« Reply #6 on: May 18, 2011, 10:42:24 am »
I'm not aware of any animation related changes in that version. Do you have a test case?

Offline shalafi

  • byte
  • *
  • Posts: 21
    • View Profile
Re: Overlay Example
« Reply #7 on: May 18, 2011, 10:44:51 am »
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:
Code: [Select]
world.addObject(object);
object.build();
The object is displayed fine without animation (animation is not set)

If I do:
Code: [Select]
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:
Code: [Select]
world.addObject(object);
object.build();
object.setAnimationSequence(animation);
object.animate(0);
The object is displayed but the animation does not work:

Offline shalafi

  • byte
  • *
  • Posts: 21
    • View Profile
Re: Overlay Example
« Reply #8 on: May 18, 2011, 10:46:54 am »
Oh, and animation is loaded like this:
Code: [Select]
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);

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Overlay Example
« Reply #9 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?

Offline shalafi

  • byte
  • *
  • Posts: 21
    • View Profile
Re: Overlay Example
« Reply #10 on: May 18, 2011, 04:00:27 pm »
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.
« Last Edit: May 18, 2011, 04:03:31 pm by shalafi »