- Düzenlendi
Change sprite on the fly (programmatically)
Hi.
Can i change sprites/images through code (libgdx backend)? If yes - how, if i know only bone name?
Thanks!
Please take a look at viewtopic.php?f=7&t=2768&p=13484 I think that is what you're looking for. Although you will need to know the name of the slot.
- Düzenlendi
Thank you!
You need to say samewhere in manual about "default" skin. I spent many hours to understand how i can work with attachment without skin
skeleton.findSlot("targetSlot").setAttachment(
skeletonData.findSkin("default").getAttachment(
skeleton.findSlotIndex("targetSlot"), "targetAttachment"
)
);
Does the same:
skeleton.setAttachment("targetSlot", "targetAttachment");
http://esotericsoftware.com/spine-using-runtimes/#Skin
All attachments that are not in a skin in Spine will appear at runtime in a skin named "default". When a skeleton needs to find an attachment by name, it first looks in its skin. If the attachment is not found, then it looks in the default skin.
There's a lot to the runtime documentation, things can get lost in all the information. I would love to write higher level documentation.
Thank you very much and sorry for my inattention!
I tried to use simple way as you said, but it looks little bit strange for me. Let me explain.
I have one skin for player. All bones have "skinnable" images except one part. This part just have attached images which i control through code. When i initialize skeleton i call:
skeleton.setSkin("player");
In this case calling "skeleton.setAttachment..." gives me:
Exception in thread "LWJGL Application" java.lang.IllegalArgumentException: Attachment not found: targetImage, for slot: targetSlot
at com.esotericsoftware.spine.Skeleton.setAttachment(Skeleton.java:257)
If i remove line "skeleton.setSkin("player");" main images doesn't visible (of course), but presumably skin now is "default", but i still have same problem (Attachment not found). If i call "skeleton.setSkin("default");", main images still invisible (of course), but now calling "skeleton.setAttachment" is works.
Look at Skeleton#getAttachment(int, String)
, it tries the skin then the default skin.
It's only one what worked for me - http://esotericsoftware.com/forum/viewt ... 646#p13646
I tried namy ways to get attachment, but i'm always have null.
Anyway - i've got what i need.
Thank you, guys!
Oh, i found why setAttachment doesn't work for me - i just forgot to remove old test line from my code
skeletonData.setDefaultSkin(skeleton.getSkin());