UnderwaterApps / overlap2d-runtime-libgdx

Overlap2D - UI and Level Editor libgdx runtime
http://overlap2d.com
Other
170 stars 96 forks source link

ButtonSystem update is overrided by LayerSystem #55

Open HuangDev opened 8 years ago

HuangDev commented 8 years ago

Hi The problem is. After I create a Button on Overlap2d tool. In code, I add ButtonComponent to Entity. After Debug. I can see the ButtonSystem is updating the button.

               if(childZComponent.layerName.equals("normal")) {
                    childMainItemComponent.visible = true;
                }
                if(childZComponent.layerName.equals("pressed")) {
                    childMainItemComponent.visible = false;
                }

But LayerSystem is updating the button too. in method updateLayers()

if(layerMapComponent.getLayer(zindexComponent.layerName) != null) {
                mainItemComponent.visible = layerMapComponent.getLayer(zindexComponent.layerName).isVisible;
            }

I think it is because the Button I created has CompositeTransformComponent too.

And I check the Engine systems. The update order is like this LayerSystem -> Overlap2dRender -> ButtonSystem.

So result is ButtonSystem is override by LayerSystem before Render.

To fix this. I can update the EntitySystem property priority. but Engine does not update order by calling systems.sort(systemComparator);

and getSystems return ImmutableArray, so I can not update order.

QuickFix:

sceneLoader.getEngine().getSystem(Overlap2dRenderer.class).priority = 1;
sceneLoader.getEngine().addSystem(new ButtonSystem());
to update the order. 

PS. English is not my strong suit. Sorry...

azakhary commented 8 years ago

I say we go for quick fix first, but probably need a better fix later on. Can you do the PR?