attached child wrong position

  ... in the unlikely case you discovered a bug, post it here.

attached child wrong position

Postby eric » Fri Sep 02, 2011 2:40 am

Hello to all,
i discovered a bug which i like to discuss.
First the code which produces the bug:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. private Shape shape;
  2. private Entity ent;
  3. public Scene onLoadScene() {
  4.         this.mEngine.registerUpdateHandler(new FPSLogger());
  5.                
  6.         this.mScene = new Scene();
  7.         this.mScene.setBackground(new ColorBackground(1,1,1));
  8.                
  9.         //ent holding a rectangle with outlines
  10.         this.ent = new Entity();
  11.         //rectangle fill
  12.         this.shape = new Rectangle(50,  50, 150, 150);
  13.        
  14.         //rectangle outlines
  15.         Line line;
  16.         line = new Line(0 , 0 , 0 , 150 , 1);
  17.         line.setColor(1, 0, 0, 1);
  18.         this.shape.attachChild(line);
  19.  
  20.         line = new Line(0 , 150 , 150 , 150 , 1);
  21.         line.setColor(1, 0, 0, 1);
  22.         this.shape.attachChild(line);
  23.  
  24.         line = new Line(150 , 150 , 150 , 0 , 1);
  25.         line.setColor(1, 0, 0, 1);
  26.         this.shape.attachChild(line);
  27.  
  28.         line = new Line(150 , 0 , 0 , 0 , 1);
  29.         line.setColor(1, 0, 0, 1);
  30.         this.shape.attachChild(line);
  31.                
  32.         this.ent.attachChild(shape);
  33.         this.mScene.attachChild(this.ent);
  34.        
  35.         //CameraScenes like using 2 controls
  36.         CameraScene sc1 = new CameraScene(this.mCamera);
  37.         sc1.setBackgroundEnabled(false);
  38.         Shape s2 = new Rectangle(       220,    220,    150,    150);
  39.         s2.setColor(0,1,0,1);
  40.         sc1.attachChild(s2);
  41.         this.mScene.setChildScene(sc1);
  42.                
  43.         CameraScene sc2 = new CameraScene(this.mCamera);
  44.         sc2.setBackgroundEnabled(false);
  45.         Shape s3 = new Rectangle(       20, 20, 20, 20);
  46.         s3.setColor(0,0,1,1);
  47.         sc2.attachChild(s3);
  48.         sc1.setChildScene(sc2);
  49.                
  50.         return this.mScene;
  51. }
  52.  
Parsed in 0.013 seconds, using GeSHi 1.0.8.4


You will see that only the first line is rendered in correct position and the others relative to the screen.

Here is my fix.
But I am not sure if it produces other problems.
I tested it with entity following camera and rotated camera and it seems to be ok.

Fixes are in CameraScene.java
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. @Override
  2. protected void onManagedDraw(final GL10 pGL, final Camera pCamera) {
  3.         if(this.mCamera != null) {
  4.                 pGL.glMatrixMode(GL10.GL_PROJECTION);
  5.                 this.mCamera.onApplyCameraSceneMatrix(pGL);
  6.                 {
  7.                         pGL.glMatrixMode(GL10.GL_MODELVIEW);
  8.                         //pGL.glPushMatrix(); // by eric render bug
  9.                         //pGL.glLoadIdentity(); // by eric render bug
  10.  
  11.                         super.onManagedDraw(pGL, pCamera);
  12.  
  13.                         pGL.glPopMatrix();
  14.                 }
  15.                 pGL.glMatrixMode(GL10.GL_PROJECTION);
  16.         }
  17. }
  18.  
Parsed in 0.010 seconds, using GeSHi 1.0.8.4


The comments are the fix.
So if someone see a problem with that pls post here.
Last edited by eric on Sun Oct 23, 2011 9:41 pm, edited 2 times in total.
eric
 
Posts: 44
Joined: Wed Feb 16, 2011 9:53 pm

Re: attached child wrong position

Postby AlexNunn » Wed Sep 14, 2011 10:27 pm

I was a bit skeptical about this when I saw it posted. Didn't bother to try and run the example code.

I added a new button bar to the bottom of one of my CameraScene's the other week. I noticed an issue where these buttons would jump to the top of the screen if a different CameraScene was attached to my main Scene. Recreating the CameraScene didn't fix it, but not attaching the other CameraScene as a child did. I remembered this post, and thought, sure, why not try the fix. What do you know... it fixed it!

I only know a few things about opengl, and I thought it weird that you comment out the push but not the pop. I tried commenting out the pop and all sorts of render issues appeared.
Granted, I've recoded my TMX rendering, so I might have something else going on too. If the example code here recreates the issue, there does seem to be a problem somewhere. Maybe an issue from when the container code was merged in?
AlexNunn
 
Posts: 604
Joined: Thu Oct 07, 2010 6:43 pm
Location: Kentucky

Re: attached child wrong position

Postby ade.se » Tue Sep 27, 2011 3:38 pm

I've noticed this issue aswell, when having two HUD's attached - one as a child of scene, and the other as a child of the first hud

The first child of the second hud renders correctly, but the second and following children of the entities will be rendered relative to the scene instead of the parent object

my hierarchy looks as follows

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. scene
  2. -------> hud 1
  3.             --------> hud 2
  4.                           ------> sprite
  5.                                        -----sprite
  6.                                        -----sprite (renders at wrong position)
  7.  
Parsed in 0.010 seconds, using GeSHi 1.0.8.4



the fix mentioned in original post works and I have not seen any side effects yet.
ade.se
 
Posts: 10
Joined: Thu Jun 16, 2011 7:16 pm

Re: attached child wrong position

Postby rageingnonsense » Wed Oct 19, 2011 10:58 pm

I wish I saw this before I posted my huge bug report just now. haha. I can confim this does indeed happen, and in addition I saw it jump back and forth depending on what was going on in the underlying scene.

I'll try your fix!
rageingnonsense
 
Posts: 16
Joined: Wed Aug 17, 2011 7:07 pm

Re: attached child wrong position

Postby ade.se » Thu Oct 20, 2011 11:51 am

yeah, the fix works, I still have not seen any side effects.
ade.se
 
Posts: 10
Joined: Thu Jun 16, 2011 7:16 pm

Re: attached child wrong position

Postby Nicolas Gramlich » Sat Oct 22, 2011 12:54 pm

Hi,

you should not attach a CameraScene to a Scene, but set it as a child scene (setChildScene) or use its subclass HUD and set it to the Camera (setHUD).

Also I cannot come up with a scenario where you'd want to have more than one CameraScene.

Best Regards,
Nicolas
Nicolas Gramlich
Site Admin
 
Posts: 1734
Joined: Mon Jun 07, 2010 6:20 pm
Location: Schriesheim, Germany

Re: attached child wrong position

Postby AlexNunn » Sun Oct 23, 2011 5:34 pm

Hmm. I attach CameraScene to my Scene's because they need to be different depending on which screen I want shown. If I set it as a HUD on the camera, I'll have to switch the HUD whenever I switch scenes. This is extra work.

I also, in the case of how I ran into the problem mentioned before, use a CameraScene to apply effects. If I'm not mistaken, camera can only have one HUD shown at a time. This would mean needing to code my HUD scene to show effects too, and the ability to immediately turn them on or off on scene change.

I guess I need to think about this some more.

Scene
|-> Effect Camera Scene
|-> HUD Scene

versus

Scene
Camera
|-> HUD + Effect Scene

Basically it's either nested scenes, or I'll have to create a HUD+effect management class. :?
AlexNunn
 
Posts: 604
Joined: Thu Oct 07, 2010 6:43 pm
Location: Kentucky

Re: attached child wrong position

Postby eric » Sun Oct 23, 2011 9:23 pm

Oh hey something is goin on here :D

I discovered the bug cuase the AnalogOnScreenControl is extended from a CameraScene.
So the example is basicly like using 2 controls.
As far as i can remember it is so cause the controls are fix on the screen ...

So if u replace the CameraScene with AnalogOnScreenControl it should produce the same problem.
This was just a breakdown.

Hope this helps in understanding this bug.
eric
 
Posts: 44
Joined: Wed Feb 16, 2011 9:53 pm

Re: attached child wrong position

Postby ober » Mon Feb 06, 2012 9:11 pm

thanks for this post
ober
 
Posts: 2
Joined: Wed Oct 26, 2011 5:05 pm

Re: attached child wrong position

Postby vertti » Tue May 08, 2012 1:55 pm

Having both a HUD attached to the camera and two AnalogOnScreenControllers attached to the scene seems to produce this effect too? This doesn't seem like a far fetched scenario so how should it be done to avoid this? Or do I really need to do that hack shown above?
Catch me on Twitter and our development blog.
Check out our game SCAWAR Space Combat and it's trailer.
Image
vertti
 
Posts: 82
Joined: Fri Jul 08, 2011 11:19 am
Location: Finland


Return to Bugs

Who is online

Users browsing this forum: No registered users and 3 guests