UnderwaterApps / overlap2d-runtime-libgdx

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

is there any demo for spine? #103

Closed yx421626416 closed 8 years ago

yx421626416 commented 8 years ago

in the editor i add a test spine animation, and add tags.when i int my code do this . sl.addComponentsByTagName("spine", SpineObjectComponent.class); it went wrong with no tags.

azakhary commented 8 years ago

Did the SpineObjectComponent have been not added to the entity? what method did you use to check that?

yx421626416 commented 8 years ago
sl.addComponentsByTagName("spine", SpineObjectComponent.class);
    SpineObjectComponent spine = rootItem.getChild("victory").getEntity()
            .getComponent(SpineObjectComponent.class);
    System.out.println("spine:" + spine);  

this is my code. i checked in the method . public void addComponentsByTagName(String tagName, Class componentClass) { ImmutableArray entities = engine.getEntities(); int i = 0; for (Entity entity : entities) { MainItemComponent mainItemComponent = ComponentRetriever.get( entity, MainItemComponent.class); // System.out.println("SceneLoader.addComponentsByTagName()");

        if (mainItemComponent == null) {
            MyLog.e("id:" + i);
            continue;
        }
        if (mainItemComponent.tags.contains(tagName)) {
            try {
                entity.add(ClassReflection
                        .<Component> newInstance(componentClass));
            } catch (ReflectionException e) {
                e.printStackTrace();
            }
        }
    }

the mainItemComponent is null when it went to here. what is the mean of 'add to the entity'?

azakhary commented 8 years ago

oh, is there a chance you do your code before scene is actually loaded (before calling loadScene) ? Because you should do your things after.

yx421626416 commented 8 years ago

yes i have called the loadScene method before i used this . ButtonComponent i have tested. it went successfully.but the spine i don't know the reason for the err. the follow is my code. sl.loadScene("MainScene", viewport); rootItem = new ItemWrapper(sl.getRoot()); sl.addComponentsByTagName("spine", SpineObjectComponent.class); SpineObjectComponent spine = rootItem.getChild("victory").getEntity() .getComponent(SpineObjectComponent.class); System.out.println("spine:" + spine);

azakhary commented 8 years ago

Oh, got it, it's because of the spine. You need to add external adapter in order to use spine at all. Check out the part of README about spine animations

azakhary commented 8 years ago

this part: Using Spine with your o2d runtime

The injection of spine factory should be before scene load, so that loading of scene actually creates the spine components. I am sorry spine is a bit hard here, reason is, they are not in maven.

yx421626416 commented 8 years ago

ok ,i got it .thanks a lot.