actor and bullet tween

This commit is contained in:
sli97
2022-12-05 23:04:17 +08:00
parent 52539376b8
commit 1b215bfbb4
2 changed files with 37 additions and 5 deletions

View File

@@ -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<any>
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) {