Spine hide/show slot/attachment

Spine hide/show slot/attachment
0.0 0

#1

Hi,
I’m trying to hide or show particular slot or attachment in spine model.

I’ve only found one working solution:

spSkeleton_setAttachment(anim->getSkeleton(), "some_attachment_name", 0);

But then I don’t know how to show attachment back (and check whether is visible).

I’ve a slot using this:
auto slotData = spSkeletonData_findSlot(anim->getState()->data->skeletonData, "some_slot_name");

but then changing a (alpha) to 0 doesn’t do anything.


#2

anyone, please :smiley: ?


#3

spSkeleton_setAttachment(anim->getSkeleton(), “some_attachment_name”, “some_attachment_image_name”);


#4

spSkeleton_getAttachmentForSlotName this returns 0 if there is no attachment


#5

Ok, maybe I don’t understand something so I’ll just show you full example. Here’s how it looks in spine:

I don’t know how can I find attachment name. The slot I want to hide is named “balon_r”.

Here’s my code:

auto attachment = spSkeleton_getAttachmentForSlotName(anim->getSkeleton(), "balon_r", "balon_r?????"); //what's the attachment name?
if(attachment == 0){
      spSkeleton_setAttachment(anim->getSkeleton(), "balon_r", "balon_r.png????"); //how can I find image name, it is in atlas, should it be the same name as is shown in spine?
}
else{
      spSkeleton_setAttachment(anim->getSkeleton(), "balon_r", 0);
}

I tried “balon_r” and “balon”.

First of all getAttachmentForSlotName always return null, because I don’t know what is the attachment name, only slot name.
Anyway this alone:

spSkeleton_setAttachment(anim->getSkeleton(), "balon_r", 0);

works.


#6
  spSkeleton_setAttachment(anim->getSkeleton(), "balon_r", "balon_r");

make sure you are using the right skin when changing the attachments


#7

im using it for all my guns like this

else if (PowerupType == PowerUpLaser)
{
FileHandler::getInstance()->PowerUp = PowerUpLaser;
spSkeleton_setAttachment(Player::getInstance()->getSkeleton(), “laserGun”, “laserGun”);

    this->schedule(schedule_selector(PlayerPowerUp::laserLogic), 0);
    str = "KER-BLASTER";
    
}

#8

the round bullet in spine is the attachment slot… the green bullet/icon is the attachment name. You have to set the right skin in order to make the attachment work


#9

I do have the right skin and it spSkeleton_getAttachmentForSlotName gives me always null.


#10

made a test case. this doesn’t work on skins… i’ll try and find a solution


#11

@piotrros you can change the opacity for now

spSlot *slot = spSkeleton_findSlot(anim->getSkeleton(), “balon_r”);
slot->a = 0;


#12

Wow, I just wanted to say I’ve already tried that, but looks like it’s working:

I was getting slot like this:

auto slotData = spSkeletonData_findSlot(anim->getState()->data->skeletonData, "balon_r");

but you suggested this:

spSlot *slot = spSkeleton_findSlot(anim->getSkeleton(), "balon_r");

and it worked, thanks a lot!!