Closed yx421626416 closed 8 years ago
Did the SpineObjectComponent have been not added to the entity? what method did you use to check that?
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
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'?
oh, is there a chance you do your code before scene is actually loaded (before calling loadScene) ? Because you should do your things after.
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);
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
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.
ok ,i got it .thanks a lot.
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.