actor and bullet tween
This commit is contained in:
		| @@ -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) { | ||||
|   | ||||
| @@ -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<any> | ||||
|   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) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user