render optimization

This commit is contained in:
sli97
2022-12-06 23:10:03 +08:00
parent 1b215bfbb4
commit b7c95c5ca9
6 changed files with 32 additions and 20 deletions

View File

@@ -23,7 +23,7 @@ export class BulletManager extends EntityManager implements IBullet {
private angle: number
private tw: Tween<any>
private targetPos: Vec3 = new Vec3
private targetPos: Vec3
init({ id, owner, type }: IBullet) {
this.id = id
@@ -34,6 +34,7 @@ export class BulletManager extends EntityManager implements IBullet {
this.fsm.init(type)
this.state = EntityStateEnum.Idle
this.node.active = false
this.targetPos = undefined
EventManager.Instance.on(EventEnum.ExplosionBorn, this.handleExplosion, this)
}
@@ -62,10 +63,10 @@ export class BulletManager extends EntityManager implements IBullet {
renderPosition(data: IBullet) {
const newPos = new Vec3(data.position.x, data.position.y)
if (!this.node.active) {
if (!this.targetPos) {
this.node.active = true
this.node.setPosition(newPos)
this.targetPos.set(newPos)
this.targetPos = new Vec3(newPos)
} else if (!this.targetPos.equals(newPos)) {
this.tw?.stop()
this.node.setPosition(this.targetPos)