Files

137 lines
3.3 KiB
JavaScript
Raw Permalink Normal View History

2026-05-23 22:10:14 +08:00
/******************************************************************
*
* 歼星迷途角色
*
******************************************************************/
const FxSpine = require( "nx.fx.spine" );
const ACTION_WALK = "float";
const ACTION_IDLE = "stand2";
const DEF_MODEL = "H30072";
cc.Class( {
extends: cc.Component,
properties: {
spAnim: { default: null, type: FxSpine },
spEft: { default: null, type: FxSpine },
spBuff: { default: null, type: FxSpine },
methyStatus:0//中毒状态 默认0
},
// 设定角色
setModel: function( _model, _cb ) {
this.points = [];
this.cbEvent = _cb;
let model = _model || DEF_MODEL;
let path = PathTool.getSpinePath( model, model, false );
this.spAnim.load( path, ( _e ) => {
if( !_e ) {
this.spAnim.action( ACTION_IDLE, true );
}
} );
},
setMethyStatus(in_methy){
this.methyStatus = in_methy;
if(in_methy == 1){
let path = PathTool.getSpinePath( "E66002", null, false );
this.spEft.load( path, ( _e ) => {
if( !_e ) {
this.spEft.action( "action", true );
}else{
this.spEft.stop();
}
} );
}else{
this.spEft.stop();
}
},
setBuffEft(eft_id){
if(!eft_id || eft_id == ""){
return;
//return this.setMethyStatus(0);
}
let spath = PathTool.getSpinePath( eft_id, null, false );
this.spBuff.load( spath, ( _e ) => {
if( !_e ) {
this.spBuff.action( "action", false, (_key,_name)=>{
// if(_key == "complete"){
// this.setMethyStatus(this.methyStatus);
// return;
// }
} );
}else{
this.spBuff.stop();
}
} );
},
// 设置位置
setPosition: function( _pos ) {
cc.Tween.stopAllByTarget( this );
this.node.position( _pos );
this.points = [];
},
// 移动路径
pushPaths: function( _pts, _reset = true ) {
// 空路径
if( nx.dt.arrEmpty( _pts ) ) {
return;
}
if( _reset ) {
this.cur = null;
this.points = [];
cc.Tween.stopAllByTarget( this.node );
}
this.points = this.points.concat( _pts );
// 下一步
this.toNext();
},
// 下一步
toNext: function() {
// 到底
if( nx.dt.arrEmpty( this.points ) ) {
nx.dt.fnInvoke( this.cbEvent, "end" );
this.spAnim.action( ACTION_IDLE, true );
return;
}
// 开始
if( !this.cur ) {
nx.dt.fnInvoke( this.cbEvent, "start" );
}
this.spAnim.action( ACTION_WALK, true );
this.cur = this.points.shift();
cc.tween( this.node )
.to( 0.5, { position: this.cur } )
.call( () => {
nx.dt.fnInvoke( this.cbEvent, "move" );
this.toNext();
} )
.start();
// 方向调整
let pos = this.node.position;
this.spAnim.node.scaleX = ( this.cur.x < pos.x ) ? -1 : 1;
},
} );