dd
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
* @LastEditors: dgflash
|
||||
* @LastEditTime: 2022-08-04 15:26:26
|
||||
*/
|
||||
import { Color, Component, EventTouch, sp, Vec3, _decorator } from "cc";
|
||||
import { Color, Component, EventTouch, sp, Vec3, _decorator ,Animation, AnimationClip, AnimationState} from "cc";
|
||||
import { LayerUtil } from "../../../../extensions/oops-plugin-framework/assets/core/utils/LayerUtil";
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
import RoleSpineAnimator from "./RoleSpineAnimator";
|
||||
@@ -16,9 +16,12 @@ const { ccclass, property } = _decorator;
|
||||
*/
|
||||
@ccclass('RoleSpine')
|
||||
export class RoleSpine extends Component {
|
||||
@property({ type: RoleSpineAnimator, tooltip: '动画控制器' })
|
||||
animator: RoleSpineAnimator = null!;
|
||||
|
||||
@property({ type: Animation, tooltip: '动画控制器' })
|
||||
animator: Animation = null!;
|
||||
atk_clip: AnimationClip = null!;
|
||||
idle_clip: AnimationClip = null!;
|
||||
move_clip: AnimationClip = null!;
|
||||
dead_clip: AnimationClip = null!;
|
||||
private spine!: sp.Skeleton;
|
||||
|
||||
onLoad() {
|
||||
@@ -26,35 +29,39 @@ export class RoleSpine extends Component {
|
||||
|
||||
this.initAnimator();
|
||||
LayerUtil.setNodeLayer(LayerUtil.MAP, this.node);
|
||||
this.atk_clip = this.animator.clips[1];
|
||||
this.idle_clip = this.animator.clips[0];
|
||||
this.move_clip = this.animator.clips[2];
|
||||
this.dead_clip = this.animator.clips[3];
|
||||
let animation = this.animator.getComponent(Animation);
|
||||
animation.on(Animation.EventType.FINISHED, this.onAnimationEvent, this)
|
||||
}
|
||||
|
||||
/** 初始化动画 */
|
||||
protected initAnimator() {
|
||||
this.spine = this.animator.getComponent(sp.Skeleton)!;
|
||||
this.animator=this.node.getChildByName("hero").getComponent(Animation);
|
||||
console.log("role view comp init",this.animator);
|
||||
|
||||
}
|
||||
onAnimationEvent(type: Animation.EventType, state: AnimationState){
|
||||
// console.log("onAnimationEvent",type,state);
|
||||
if(type==Animation.EventType.FINISHED){
|
||||
if(state.name==this.atk_clip.name){
|
||||
this.idle();
|
||||
}
|
||||
}
|
||||
}
|
||||
atk() {
|
||||
this.spine.setAnimation(0, "atk2", false);
|
||||
if(!this.animator.getState(this.atk_clip.name).isPlaying){
|
||||
this.animator.play(this.atk_clip.name);
|
||||
}
|
||||
}
|
||||
|
||||
magic() {
|
||||
this.spine.setAnimation(0, "max", false);
|
||||
}
|
||||
setSkin(value: string): void {
|
||||
console.log("RoleSpine setSkin", value);
|
||||
this.spine.setSkin(value);
|
||||
}
|
||||
play(animName: string, loop: boolean): void {
|
||||
this.spine.setAnimation(0, animName, loop);
|
||||
}
|
||||
setAlpha(value: number): void {
|
||||
var color: Color = this.spine.color;
|
||||
color.a = 255 * (value / 1);
|
||||
this.spine.color = color;
|
||||
|
||||
}
|
||||
|
||||
setPos(value: Vec3): void {
|
||||
this.node.position = value;
|
||||
}
|
||||
|
||||
|
||||
checkTouch(event: EventTouch): boolean {
|
||||
return false;
|
||||
@@ -69,6 +76,8 @@ export class RoleSpine extends Component {
|
||||
}
|
||||
|
||||
idle() {
|
||||
|
||||
if(!this.animator.getState(this.idle_clip.name).isPlaying){
|
||||
this.animator.play(this.idle_clip.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user