spine 局部换装

spine 换装接口 setAttachment

首先你在制作骨骼的时候,需要给一个 slot 设置多个 attachment,spine在一个时刻只会显示其中的一个 attachment,动态切换 attachment 调用 SkeletonRenderer::setAttachment接口。这个接口自动绑定并未提供,社区版手动绑定提供给开发者使用。

 

接口示例:(注:只有第一个参数时,表示去掉slot的Attachment,不显示图片)

local hero = sp.SkeletonAnimation:create("build_yellowlightfinished.json", "build_yellowlightfinished.atlas")
hero:setAttachment("changegun", "pc_gungirl_crossbow3")

 

c++:

SkeletonRenderer.cpp

bool SkeletonRenderer::setAttachment (const std::string& slotName, const std::string& attachmentName) {
	return spSkeleton_setAttachment(_skeleton, slotName.c_str(), attachmentName.empty() ? 0 : attachmentName.c_str()) ? true : false;
}

Skeleton.c

int spSkeleton_setAttachment (spSkeleton* self, const char* slotName, const char* attachmentName) {
	int i;
	for (i = 0; i < self->slotsCount; ++i) {
		spSlot *slot = self->slots[i];
		if (strcmp(slot->data->name, slotName) == 0) {
			if (!attachmentName)
				spSlot_setAttachment(slot, 0);
			else {
				spAttachment* attachment = spSkeleton_getAttachmentForSlotIndex(self, i, attachmentName);
				if (!attachment) return 0;
				spSlot_setAttachment(slot, attachment);
			}
			return 1;
		}
	}
	return 0;
}
void spSlot_setAttachment (spSlot* self, spAttachment* attachment) {
	if (attachment == self->attachment) return;
	CONST_CAST(spAttachment*, self->attachment) = attachment;
	SUB_CAST(_spSlot, self)->attachmentTime = self->bone->skeleton->time;
	self->attachmentVerticesCount = 0;
}

 

总结:

制作spine时 一个插槽slot上需要预制多个attachment附件,需要切换显示时 调用setAttachment方法,第一个参数slotName,第二个参数 attachmentName。

最终是spSlot对象 调用了spSlot_setAttachment方法。

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值