手动控制spine 动画
This commit is contained in:
@@ -65,9 +65,6 @@ export class MapViewComp extends CCComp {
|
||||
var test7 = ecs.getEntity<Role>(Role);
|
||||
test7.load(this.aStarToVec3("360,-60"), true);
|
||||
}
|
||||
else {
|
||||
this.scene.setPlayer(pos);
|
||||
}
|
||||
}
|
||||
|
||||
private aStarToVec3(str: string) {
|
||||
|
||||
@@ -2,11 +2,8 @@ import { Camera, CCBoolean, Component, EventTouch, Node, screen, Size, Texture2D
|
||||
import { oops } from "../../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
||||
import MapData from "./map/base/MapData";
|
||||
import { MapLoadModel } from "./map/base/MapLoadModel";
|
||||
import MapParams from "./map/base/MapParams";
|
||||
import Charactor from "./map/charactor/Charactor";
|
||||
import EntityLayer from "./map/layer/EntityLayer";
|
||||
import MapLayer from "./map/layer/MapLayer";
|
||||
import IRoadSeeker from "./map/road/IRoadSeeker";
|
||||
import RoadNode from "./map/road/RoadNode";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
@@ -39,24 +36,9 @@ export class MapViewScene extends Component {
|
||||
ratio: Vec2 = new Vec2();
|
||||
|
||||
private _roadDic: { [key: string]: RoadNode } = {};
|
||||
private _roadSeeker!: IRoadSeeker;
|
||||
private _mapParams: MapParams | null = null;
|
||||
|
||||
private player: Charactor | null = null; // 主角玩家
|
||||
private targetPos: Vec3 = new Vec3(); // 摄像机位置
|
||||
private winSize!: Size; // 屏幕尺寸
|
||||
private screenCenter: Vec3 = new Vec3(); // 屏幕中心位置
|
||||
private boundary: Vec2 = new Vec2(); // 边界位置
|
||||
|
||||
setPlayer(value: Charactor | Vec3) {
|
||||
if (value instanceof Charactor) {
|
||||
this.enabled = true;
|
||||
this.player = value;
|
||||
}
|
||||
else {
|
||||
this.player!.pos = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
onLoad() {
|
||||
this.enabled = false;
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
*/
|
||||
import { Component, Node, _decorator } from 'cc';
|
||||
import { Timer } from '../../../../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer';
|
||||
import Charactor from '../charactor/Charactor';
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@@ -21,15 +20,16 @@ export default class EntityLayer extends Component {
|
||||
private timer: Timer = new Timer(0.2);
|
||||
|
||||
update(dt: number) {
|
||||
if (this.timer.update(dt))
|
||||
this.node.children.sort(this.zIndexSort);
|
||||
this.timer.update(dt)
|
||||
// if (this.timer.update(dt))
|
||||
// this.node.children.sort(this.zIndexSort);
|
||||
}
|
||||
|
||||
private zIndexSort(a: Node, b: Node) {
|
||||
let a_zIndex = a.getComponent(Charactor)!.zIndex;
|
||||
let b_zIndex = b.getComponent(Charactor)!.zIndex;
|
||||
return a_zIndex - b_zIndex;
|
||||
}
|
||||
// private zIndexSort(a: Node, b: Node) {
|
||||
// let a_zIndex = a.getComponent(Charactor)!.zIndex;
|
||||
// let b_zIndex = b.getComponent(Charactor)!.zIndex;
|
||||
// return a_zIndex - b_zIndex;
|
||||
// }
|
||||
|
||||
public clear() {
|
||||
this.node.children.forEach(n => {
|
||||
|
||||
@@ -11,7 +11,6 @@ import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/O
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { UIID } from "../common/config/GameUIConfig";
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
import Charactor from "../map/view/map/charactor/Charactor";
|
||||
import { RoleModelComp } from "./model/RoleModelComp";
|
||||
import { RoleSpine } from "./view/RoleSpine";
|
||||
import { RoleViewComp } from "./view/RoleViewComp";
|
||||
@@ -47,8 +46,6 @@ export class Role extends ecs.Entity {
|
||||
this.add(mv);
|
||||
var as = node.getComponent(RoleSpine);
|
||||
// as.setSkin(skin);
|
||||
// as.setPlayer(pos);
|
||||
|
||||
if (isMonster) {
|
||||
node.setScale(-1, 1, 1);
|
||||
}
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
/** 角色动作名 */
|
||||
export enum RoleAnimatorType {
|
||||
/** 待机 */
|
||||
Idle = "Idle",
|
||||
idle = "idle",
|
||||
/** 攻击 */
|
||||
Attack = "Attack",
|
||||
act1 = "act1",
|
||||
/** 受击 */
|
||||
Hurt = "Hurt",
|
||||
magic1 = "magic1",
|
||||
/** 死亡 */
|
||||
Dead = "Dead"
|
||||
move = "move"
|
||||
}
|
||||
@@ -7,8 +7,6 @@
|
||||
import { Color, Component, EventTouch, sp, Vec3, _decorator } from "cc";
|
||||
import { LayerUtil } from "../../../../../extensions/oops-plugin-framework/assets/core/utils/LayerUtil";
|
||||
import { smc } from "../../common/SingletonModuleComp";
|
||||
import Charactor, { CharactorDirection, CharactorState } from "../../map/view/map/charactor/Charactor";
|
||||
import { ICharactorClip } from "../../map/view/map/charactor/ICharactorClip";
|
||||
import RoleSpineAnimator from "./RoleSpineAnimator";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
@@ -17,55 +15,29 @@ const { ccclass, property } = _decorator;
|
||||
* RPG SPINE角色模型
|
||||
*/
|
||||
@ccclass('RoleSpine')
|
||||
export class RoleSpine extends Component implements ICharactorClip {
|
||||
export class RoleSpine extends Component {
|
||||
@property({ type: RoleSpineAnimator, tooltip: '动画控制器' })
|
||||
animator: RoleSpineAnimator = null!;
|
||||
|
||||
private spine!: sp.Skeleton;
|
||||
private charactor!: Charactor;
|
||||
|
||||
onLoad() {
|
||||
// 角色控制组件
|
||||
// this.charactor = this.addComponent(Charactor)!;
|
||||
|
||||
this.initAnimator();
|
||||
|
||||
LayerUtil.setNodeLayer(LayerUtil.MAP, this.node);
|
||||
this.idle();
|
||||
}
|
||||
|
||||
/** 初始化动画 */
|
||||
protected initAnimator() {
|
||||
this.spine = this.animator.getComponent(sp.Skeleton)!;
|
||||
this.spine.setSkin('war');
|
||||
}
|
||||
|
||||
setPlayer(pos: Vec3) {
|
||||
// var scene = smc.map.MapView.scene;
|
||||
// this.node.parent = scene.entityLayer!.node!;
|
||||
// this.charactor.clip = this;
|
||||
// this.charactor.sceneMap = scene;
|
||||
this.charactor.pos = pos;
|
||||
this.charactor.updateZIndex();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
setDirection(value: CharactorDirection): void {
|
||||
if (value > 4) {
|
||||
this.animator!.node.setScale(-1, 1, 1);
|
||||
}
|
||||
else {
|
||||
this.animator!.node.setScale(1, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
setState(value: CharactorState): void {
|
||||
switch (value) {
|
||||
case CharactorState.Idle:
|
||||
this.idle();
|
||||
break;
|
||||
case CharactorState.Run:
|
||||
this.walk();
|
||||
break;
|
||||
}
|
||||
}
|
||||
setSkin(value: string): void {
|
||||
this.spine.setSkin(value);
|
||||
}
|
||||
@@ -89,10 +61,10 @@ export class RoleSpine extends Component implements ICharactorClip {
|
||||
}
|
||||
|
||||
walk() {
|
||||
this.animator!.setNumber("Speed", 1);
|
||||
|
||||
}
|
||||
|
||||
idle() {
|
||||
this.animator!.setNumber("Speed", 0);
|
||||
this.animator!.play("idle");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,7 @@
|
||||
* @LastEditors: dgflash
|
||||
* @LastEditTime: 2022-08-04 15:26:38
|
||||
*/
|
||||
import { sp, _decorator } from "cc";
|
||||
import AnimatorSpine from "../../../../../extensions/oops-plugin-framework/assets/libs/animator/AnimatorSpine";
|
||||
import Charactor, { CharactorDirection } from "../../map/view/map/charactor/Charactor";
|
||||
import { sp, _decorator ,Component} from "cc";
|
||||
|
||||
const { ccclass, property, requireComponent, disallowMultiple } = _decorator;
|
||||
|
||||
@@ -16,24 +14,28 @@ const { ccclass, property, requireComponent, disallowMultiple } = _decorator;
|
||||
@ccclass
|
||||
@disallowMultiple
|
||||
@requireComponent(sp.Skeleton)
|
||||
export default class RoleSpineAnimator extends AnimatorSpine {
|
||||
private charactor!: Charactor;
|
||||
private dir: CharactorDirection = CharactorDirection.bottom;
|
||||
export default class RoleSpineAnimator extends Component {
|
||||
private animName: string = "idle";
|
||||
private loop: boolean = true;
|
||||
|
||||
start() {
|
||||
this.charactor = this.node.parent!.getComponent(Charactor)!;
|
||||
super.start();
|
||||
console.log("RoleSpineAnimator start");
|
||||
this.playAnimation(this.animName, this.loop);
|
||||
}
|
||||
|
||||
lateUpdate(dt: number) {
|
||||
if (this.dir != this.charactor.direction) {
|
||||
this.dir = this.charactor.direction;
|
||||
this.playAnimation(this.animName, this.loop);
|
||||
}
|
||||
this.playAnimation(this.animName, this.loop);
|
||||
|
||||
}
|
||||
|
||||
play(animName: string, loop: boolean) {
|
||||
if (animName) {
|
||||
this.animName = animName;
|
||||
this.loop = loop;
|
||||
}
|
||||
else {
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 播放动画
|
||||
* @override
|
||||
@@ -44,29 +46,9 @@ export default class RoleSpineAnimator extends AnimatorSpine {
|
||||
if (animName) {
|
||||
this.animName = animName;
|
||||
this.loop = loop;
|
||||
|
||||
// animName = `huaxian/${this.getDirection(this.charactor.direction)}${animName}`;
|
||||
this._spine.setAnimation(0, animName, loop);
|
||||
}
|
||||
else {
|
||||
this._spine.clearTrack(0);
|
||||
}
|
||||
}
|
||||
|
||||
private getDirection(dir: CharactorDirection): string {
|
||||
let dirName = "";
|
||||
if (dir == CharactorDirection.up) {
|
||||
dirName = "back";
|
||||
}
|
||||
else if (dir == CharactorDirection.bottom) {
|
||||
dirName = "positive";
|
||||
}
|
||||
else if (dir == CharactorDirection.left || dir == CharactorDirection.left_up || dir == CharactorDirection.left_bottom) {
|
||||
dirName = "side";
|
||||
}
|
||||
else if (dir == CharactorDirection.right || dir == CharactorDirection.right_up || dir == CharactorDirection.right_bottom) {
|
||||
dirName = "side";
|
||||
}
|
||||
return dirName;
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,6 @@
|
||||
import { Vec3, _decorator } from "cc";
|
||||
import { ecs } from "../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { CCComp } from "../../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
||||
import Charactor from "../../map/view/map/charactor/Charactor";
|
||||
import { RoleSpine } from "./RoleSpine";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
@@ -20,12 +19,10 @@ export class RoleViewComp extends CCComp {
|
||||
/** 角色动画 */
|
||||
as: RoleSpine = null!;
|
||||
/** 角色控制器 */
|
||||
charactor: Charactor = null!;
|
||||
|
||||
/** 视图层逻辑代码分离演示 */
|
||||
onLoad() {
|
||||
this.as = this.getComponent(RoleSpine);
|
||||
this.charactor = this.getComponent(Charactor);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -7,30 +7,18 @@
|
||||
|
||||
import { Component, v3, _decorator } from "cc";
|
||||
import { smc } from "../../common/SingletonModuleComp";
|
||||
import Charactor from "../../map/view/map/charactor/Charactor";
|
||||
import MapRoadUtils from "../../map/view/map/road/MapRoadUtils";
|
||||
import RoadNode from "../../map/view/map/road/RoadNode";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('RoleViewOwn')
|
||||
export class RoleViewOwn extends Component {
|
||||
private charactor!: Charactor;
|
||||
|
||||
onLoad() {
|
||||
this.charactor = this.getComponent(Charactor)!;
|
||||
this.node.on(Charactor.NextRoadNode, this.onNextRoadNode, this);
|
||||
|
||||
}
|
||||
|
||||
private onNextRoadNode(rn: RoadNode) {
|
||||
var key: string = rn.dx + "," + rn.dy;
|
||||
var mv = smc.map.MapView;
|
||||
var delivery = mv.deliverys.get(key);
|
||||
if (delivery && mv.isTransfer == false) {
|
||||
this.charactor.stop();
|
||||
mv.transfer(delivery.toMapId, this.aStarToVec3(delivery.start));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private aStarToVec3(str: string) {
|
||||
let array = str.split(",");
|
||||
|
||||
Reference in New Issue
Block a user