Hi, I am a beginer in spine. I create a game which use libGDX + spine. The player controls a hero to attack monsters. I want the hero to change different weapons or hold a shield. How do i do this with spine 2d.Do I need to put all weapons to the spine atlas and set the active weapon visible and hide all others or any other solution? Thanks.
How to change a spine character's weapon in his hand.
- Uređeno
caizhikun wroteDo I need to put all weapons to the spine atlas and set the active weapon visible and hide all others
That is the simple and straightforward way to do it, and the way I would suggest to start. If you have hundreds of weapons that don't fit in an atlas page AND using multiple atlas pages causes too many draw calls, only then would I consider something fancier. Eg, you can determine which images you need to display your character's configuration, then generate an atlas at runtime (see PixmapPacker) using only those images.
Thanks for reponses.
1. If the hero can equip something else, such as helmet , cloak , armors. the solution seems to be not good , the atlas would become very large. I see there is an Attachmenet interfact in spine code ,it seems to fit what I need that attach different armors to different part of the hero's body. But I don't know how to use it. Do is missunderstand the Attachment ?
You mentioned that I can generate a pixmap at runtime and construct an TextureAtlas , the atlas would only contains the attachment images , but how do i merge this atlas to the skeleton's atlas?
atlas = new TextureAtlas(Gdx.files.internal("spineboy/spineboy.atlas")); SkeletonJson json = new SkeletonJson(atlas); // This loads skeleton JSON data, which is stateless. json.setScale(0.6f); // Load the skeleton at 60% the size it was in Spine. SkeletonData skeletonData = json.readSkeletonData(Gdx.files.internal("spineboy/spineboy.json"));
That's common problem for many projects. For that kind of tricks runtimes need better integration with target engines, thats why current strategy is "Every runtime is for themselves", there is no common API.
pixi.js runtime gives provides a way to change a texture without changing attachment or slot.
caizhikun wrote1. If the hero can equip something else, such as helmet , cloak , armors. the solution seems to be not good , the atlas would become very large.
Only until the atlas becomes too large do you have a problem.
caizhikun wroteI see there is an Attachmenet interfact in spine code ,it seems to fit what I need that attach different armors to different part of the hero's body. But I don't know how to use it. Do is missunderstand the Attachment ?
You can create attachments programmatically. You'll need to design your art so that you know where to place the attachment on the bone. Usually this is done by creating one piece of art for each part of your skeleton, attach that in Spine, then replace the art with a programmatically generated attachment at runtime. This means each piece of art will have the same attachment position on the bone, so the art needs to be designed with that in mind (eg attachment / pivot point is the same for all images). You can use a larger image than needed with whitespace so your other attachments have room without changing the attachment point.
caizhikun wrote2. You mentioned that I can generate a pixmap at runtime and construct an TextureAtlas , the atlas would only contains the attachment images , but how do i merge this atlas to the skeleton's atlas?
A skeleton doesn't have an atlas, AtlasAttachmentLoader does. When you do new SkeletonJson(Atlas)
it is creating an AtlasAttachmentLoader for you, but you aren't required to use this. You can use new SkeletonJson(AttachmentLoader)
. The AttachmentLoader controls where attachments find images/regions. You can implement your own so all attachments are created but not populated with regions, then you can populate the attachments you are actually using yourself. Or you can create an atlas with only the regions you will use (eg using PixmapPacker) and continue using AtlasAttachmentLoader.
Thank you, Hackerham and Nate. I have a clearer understanding of the spine and bone animation now.
If that is of any help to you @caizhikun, here is how I do it:
// called each time my hero is created or change his equipment.
public void updateSkin() {
skeletonAnimation.Skeleton.SetAttachment("weapon", "melee/" + Equipment.get("weapon"));
skeletonAnimation.Skeleton.SetAttachment("shield", "shield/" + Equipment.get("shield"));
skeletonAnimation.Skeleton.SetAttachment("bow", "range/" + Equipment.get("bow"));
// etc. idem for armor
// In my real code I use Constants as Identifier (less error prone)
}
Equipment is just a Class that store different strings according to what my hero is currently supposed to wear.
The cool part is, I have put the images used by Spine in Resource file of Unity (eg "Resource/skin/melee/swordIron"). Which means I can also load those image for my Equipment Menu icon for example.
Hi there !
I know the subject is kinda old now but maybe it's better to "up" it rather than creating a new one ?
Anyway, how would you manage the weapon's properties by only switching attachments ?
I used to work with spritesheet and I had like a whole "transform weapon" parenting different weapons children enabled/disabled, these children were containing the different properties and hit colliders animations.
Weapon properties (like damage dealt) are application specific. You probably want to store this game data separately from your animations. You wouldn't want to have to open Spine to change your game data.
Hi there,
I have same problematic, i need a confirmation if my process is good.
I have idea to realize this operation :
I create all model type of weapon in the spine
- Blade - weapon
Short Blade : 1 dagger
Normal Blade : Sword - Gun
Short Gun
Normal Gun
Long Gun - Gun 2 hands need
...
All type of weapon have specific bounding box for event hit, etc... The bounding box is define in Spine.
bboxShortBlade
bboxNormalBlade
bboxLongBlade
Each type of weapon have Specific animation.
When a weapon is selected, i use the good bounding box i need, and i replace the model weapon by the weapon selected.
with this method :
I think use skin is not require, perhaps we have better solution to realize this operation quickly but i have follow the mixed example.... Spine.Attachment baseAttachment = baseSkin.GetAttachment("commonWeaponAttachment", "shortBlade"); Spine.Attachment newAttachment = baseAttachment.GetRemappedClone(newWeaponSprite, sourceMaterial); customSkin.SetAttachment("commonWeaponAttachment", "shortBlade", newAttachment); skeleton.SetSlotsToSetupPose(); skeletonAnimation.Update(0); ...
My question it is good process to realize this operation? (Create type of weapon and bounding box in Spine)
Hey @timactive!
You seem to be using Unity.
Please do specify this next time.
Using a custom skin at runtime allows you to not affect other instances of that same skeleton, since each skeleton can use its own custom skin.
It also allows animations to keep working correctly since animations (if they are keyed) use skins as the source of what attachment to use.
It's also sometimes easier to organize if you use skins in Spine editor.