82 lines
1.7 KiB
JavaScript
82 lines
1.7 KiB
JavaScript
|
|
/******************************************************************
|
||
|
|
*
|
||
|
|
* 卧室角色展示
|
||
|
|
*
|
||
|
|
******************************************************************/
|
||
|
|
|
||
|
|
const FxSpine = require( "nx.fx.spine" );
|
||
|
|
|
||
|
|
// 部位动画配置
|
||
|
|
const IDLE = "action";
|
||
|
|
|
||
|
|
cc.Class( {
|
||
|
|
|
||
|
|
extends: cc.Component,
|
||
|
|
|
||
|
|
properties: {
|
||
|
|
|
||
|
|
spAnim: { default: null, type: FxSpine },
|
||
|
|
auVoices: { default: [], type: cc.AudioClip },
|
||
|
|
},
|
||
|
|
|
||
|
|
// 显示
|
||
|
|
onEnable: function() {
|
||
|
|
|
||
|
|
// 播放待机动画
|
||
|
|
this.partName = "";
|
||
|
|
this.spAnim.action( IDLE, true );
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
// 回调绑定
|
||
|
|
bindTouch: function( _cb ) {
|
||
|
|
this.cbTouch = _cb;
|
||
|
|
},
|
||
|
|
|
||
|
|
// 设置动作集
|
||
|
|
setActions: function( _acts ) {
|
||
|
|
this.actions = _acts;
|
||
|
|
},
|
||
|
|
|
||
|
|
// 播放动作
|
||
|
|
doAction: function( _act ) {
|
||
|
|
this.onTouchPart( _act || IDLE );
|
||
|
|
},
|
||
|
|
|
||
|
|
// 点击部位
|
||
|
|
onTouchPart: function( _akey ) {
|
||
|
|
|
||
|
|
// 正在播放
|
||
|
|
if( this.current ) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 未解锁动作
|
||
|
|
let info = this.actions ? this.actions[ _akey ] : null;
|
||
|
|
if( !info ) {
|
||
|
|
nx.tbox( "动作未解锁" );
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 播放动作
|
||
|
|
this.current = info;
|
||
|
|
this.spAnim.action( this.current.action, false, ( _event ) => {
|
||
|
|
if( _event == "complete" ) {
|
||
|
|
this.current = null;
|
||
|
|
this.spAnim.action( IDLE, true );
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
} );
|
||
|
|
|
||
|
|
// 播放音效
|
||
|
|
let clip = this.auVoices[ this.current.voice ];
|
||
|
|
if( clip ) {
|
||
|
|
nx.audio.playVoice( clip );
|
||
|
|
}
|
||
|
|
|
||
|
|
nx.dt.fnInvoke( this.cbTouch, _akey );
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
} );
|