fix:编辑器文件导入. add:example,runtime
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
import AnimatorSpine from "../../animator/AnimatorSpine";
|
||||
import AnimatorSpineSecondary from "../../animator/AnimatorSpineSecondary";
|
||||
|
||||
const { ccclass, property } = cc._decorator;
|
||||
|
||||
@ccclass
|
||||
export default class SpineScene extends cc.Component {
|
||||
@property(sp.Skeleton) SpineBoy: sp.Skeleton = null;
|
||||
|
||||
private _updateSpeed: boolean = false;
|
||||
private _speed: number = 0;
|
||||
private _animatorMain: AnimatorSpine = null;
|
||||
private _animatorSecondary: AnimatorSpineSecondary[] = [];
|
||||
|
||||
protected onLoad() {
|
||||
this._animatorMain = this.SpineBoy.getComponent(AnimatorSpine);
|
||||
this._animatorMain.onInit((fromState: string, toState: string) => {
|
||||
cc.log(`state change: ${fromState} -> ${toState}`);
|
||||
});
|
||||
this._animatorSecondary = this.SpineBoy.getComponents(AnimatorSpineSecondary);
|
||||
|
||||
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this);
|
||||
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_UP, this.onKeyUp, this);
|
||||
}
|
||||
|
||||
protected update(dt: number) {
|
||||
this._speed = this._updateSpeed ? Math.min(5, this._speed + dt) : Math.max(0, this._speed - dt * 2);
|
||||
this._animatorMain.setNumber('speed', this._speed);
|
||||
}
|
||||
|
||||
protected onDestroy() {
|
||||
cc.systemEvent.off(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this);
|
||||
cc.systemEvent.off(cc.SystemEvent.EventType.KEY_UP, this.onKeyUp, this);
|
||||
}
|
||||
|
||||
private onKeyDown(event: cc.Event.EventKeyboard) {
|
||||
let code: cc.macro.KEY = event.keyCode;
|
||||
switch (code) {
|
||||
case cc.macro.KEY.left:
|
||||
case cc.macro.KEY.right:
|
||||
this._updateSpeed = true;
|
||||
break;
|
||||
case cc.macro.KEY.space:
|
||||
this._animatorMain.autoTrigger('jump');
|
||||
break;
|
||||
case cc.macro.KEY.k:
|
||||
this._animatorSecondary[0].autoTrigger('shoot');
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private onKeyUp(event: cc.Event.EventKeyboard) {
|
||||
let code: cc.macro.KEY = event.keyCode;
|
||||
switch (code) {
|
||||
case cc.macro.KEY.left:
|
||||
case cc.macro.KEY.right:
|
||||
this._updateSpeed = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"uuid": "1810c37f-1e5a-41ec-b2ba-e78ac9b155e0",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
Reference in New Issue
Block a user