当前位置: 首页 > 工具软件 > Spine Mobile > 使用案例 >

Spine动画

鲜于子琪
2023-12-01

添加Spine动画需要用到 SkeletonAnimation 它相当于Node

所以它的使用就和使用Sprite一样

	m_skeletonNode = SkeletonAnimation::createWithFile("spine/spineboy.json", "spine/spineboy.atlas");
	
	m_skeletonNode->setMix("walk", "jump", 0.2f); // 混合动作,第三个参数是混合动画的时间
	//m_skeletonNode->setMix("jump", "walk", 0.4f);

	m_skeletonNode->setAnimation(0, "walk", false); // 设置动画walk,第一个参数为优先级,越高越先
	m_skeletonNode->addAnimation(0, "jump", false/*, 3.f*/); // 添加动画jump, 第四个参数是延迟

	m_skeletonNode->timeScale = 0.3f;   // 动画速度变缓
	m_skeletonNode->debugBones = true;  // 打开骨骼调试

	m_skeletonNode->setPosition(winSize.width/2, winSize.height/2);
	this->addChild(m_skeletonNode);

其中动作混合可以将一个动作加到另一个动作之上,这样可以使动作更加连贯。这是目前Cocostudio没有的。


动作状态事件的添加:

m_skeletonNode->setAnimationListener(this, animationStateEvent_selector(SpineTestLayer::animationStateEvent));

回调函数如下:

void SpineTestLayer::animationStateEvent( spine::SkeletonAnimation *node, int trackIndex, spEventType type, spEvent* event, int loopCount )
{
	spTrackEntry* entry = spAnimationState_getCurrent(node->state, trackIndex);
	const char* animationName = (entry && entry->animation) ? entry->animation->name : 0;

	switch (type) {
	case ANIMATION_START:
		log("%d start: %s", trackIndex, animationName);
		break;
	case ANIMATION_END:
		log("%d end: %s", trackIndex, animationName);
		break;
	case ANIMATION_COMPLETE:
		log("%d complete: %s, %d", trackIndex, animationName, loopCount);
		break;
	case ANIMATION_EVENT:
		log("%d event: %s, %s: %d, %f, %s", trackIndex, animationName, event->data->name, event->intValue, event->floatValue, event->stringValue);
		break;
	}
}


 类似资料: