Cocos creator Spine常用API
常用API
var spine = this.node.children[0].getComponent(sp.Skeleton)
//spine开始播放监听,需要注意的事,如果使用setAniamtion播放动画的话
//监听需要放在setAniamtion之前,不然触发不了
spine.setStartListener(() => {
cc.log("sipne开始播放监听")
})
//播放
spine.setAnimation(0, "1", false)
//是否停止,可以设置paused的布尔值来暂停播放spine
var isStop = spine.paused
cc.log("是否暂停spine动画: "+isStop)
//spine动画播放完后的事件监听。
spine.setEndListener(() => {
//如果用不了,建议使用setCompleteListener
cc.log("spine动画播放完后的事件监听。")
})
//spine播放过程中的监听--spine帧事件
spine.setEventListener(() => {
cc.log("spine播放过程中的监听")
})
//spine循环播放完一次的监听
spine.setCompleteListener(() => {
spine.paused = true
cc.log("spine循环播放完一次的监听")
let isStop = spine.paused
cc.log("是否暂停spine动画: " + isStop)
})
Spine 基本介绍
个人理解
- spine组成:骨架–>骨骼–>插槽–>附件(图片之类)
- 一个插槽可以有多个附件,但一个插槽只能显示一个附件(Cocos creator提供API可以修改附件)
- DragonBones组成好像与spine一样
//spine动画,spine骨架,骨骼,插槽,附件
Attachment(){
var spine = this.node.children[0].getComponent(sp.Skeleton)
//修改插槽的附件
spine.setAttachment("baomihua1", "附件名");
}
隐藏插槽
var spine = this.kell.getComponent(sp.Skeleton);
var soltName = spine.findSlot("bu03");
//隐藏插槽
// soltName.color = new cc.Color(0,0,0,0)
// soltName.color = cc.color(0,0,0,0)
spine.setAttachment("bu02", null)
spine.setAttachment("bu01", null)
spine.setAttachment("bu03", null)