/****************************************************************** * * 大富翁角色 * ******************************************************************/ 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 }, }, // 设定角色 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 ); } } ); }, // 设置位置 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( () => { this.toNext(); } ) .start(); // 方向调整 let pos = this.node.position; this.spAnim.node.scaleX = ( this.cur.x < pos.x ) ? -1 : 1; }, } );