From 1b215bfbb4184eb8a9c889e772ccb0cbf8d63024 Mon Sep 17 00:00:00 2001 From: sli97 <775303361@qq.com> Date: Mon, 5 Dec 2022 23:04:17 +0800 Subject: [PATCH] actor and bullet tween --- .../Scripts/Entity/Actor/ActorManager.ts | 21 +++++++++++++++++-- .../Scripts/Entity/Bullet/BulletManager.ts | 21 ++++++++++++++++--- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/apps/client/assets/Scripts/Entity/Actor/ActorManager.ts b/apps/client/assets/Scripts/Entity/Actor/ActorManager.ts index eaab0ef..bcb0281 100644 --- a/apps/client/assets/Scripts/Entity/Actor/ActorManager.ts +++ b/apps/client/assets/Scripts/Entity/Actor/ActorManager.ts @@ -1,4 +1,4 @@ -import { _decorator, instantiate, ProgressBar, Label } from 'cc'; +import { _decorator, instantiate, ProgressBar, Label, Vec3, Tween, tween } from 'cc'; import { EntityManager } from '../../Base/EntityManager'; import { ApiMsgEnum, EntityTypeEnum, IActor, InputTypeEnum, IVec2, toFixed } from '../../Common'; import { EntityStateEnum } from '../../Enum'; @@ -27,6 +27,9 @@ export class ActorManager extends EntityManager implements IActor { private label: Label private weapon: WeaponManager + private tw: Tween + private targetPos: Vec3 + get isSelf() { return DataManager.Instance.myPlayerId === this.id } @@ -85,7 +88,21 @@ export class ActorManager extends EntityManager implements IActor { } renderPosition(data: IActor) { - this.node.setPosition(data.position.x, data.position.y) + // this.node.setPosition(data.position.x, data.position.y) + + const newPos = new Vec3(data.position.x, data.position.y) + if (!this.targetPos) { + this.node.setPosition(newPos) + this.targetPos = new Vec3() + this.targetPos.set(newPos) + } else if (!this.targetPos.equals(newPos)) { + this.tw?.stop() + this.node.setPosition(this.targetPos) + this.targetPos.set(newPos) + this.tw = tween(this.node).to(0.1, { + position: this.targetPos + }).start() + } } renderDirection(data: IActor) { diff --git a/apps/client/assets/Scripts/Entity/Bullet/BulletManager.ts b/apps/client/assets/Scripts/Entity/Bullet/BulletManager.ts index 79dc292..82ff92d 100644 --- a/apps/client/assets/Scripts/Entity/Bullet/BulletManager.ts +++ b/apps/client/assets/Scripts/Entity/Bullet/BulletManager.ts @@ -1,4 +1,4 @@ -import { _decorator } from 'cc' +import { Tween, tween, Vec3, _decorator } from 'cc' import { EntityManager } from '../../Base/EntityManager' import { EntityTypeEnum, IBullet, IVec2 } from '../../Common' import { EntityStateEnum, EventEnum } from '../../Enum' @@ -22,6 +22,8 @@ export class BulletManager extends EntityManager implements IBullet { direction: IVec2 private angle: number + private tw: Tween + private targetPos: Vec3 = new Vec3 init({ id, owner, type }: IBullet) { this.id = id @@ -54,13 +56,26 @@ export class BulletManager extends EntityManager implements IBullet { } render(data: IBullet) { - this.node.active = true this.renderPosition(data) this.renderDirection(data) } renderPosition(data: IBullet) { - this.node.setPosition(data.position.x, data.position.y) + const newPos = new Vec3(data.position.x, data.position.y) + if (!this.node.active) { + this.node.active = true + this.node.setPosition(newPos) + this.targetPos.set(newPos) + } else if (!this.targetPos.equals(newPos)) { + this.tw?.stop() + this.node.setPosition(this.targetPos) + this.targetPos.set(newPos) + this.tw = tween(this.node).to(0.1, { + position: this.targetPos + }).start() + } + + // this.node.setPosition(data.position.x, data.position.y) } renderDirection(data: IBullet) {