actor and bullet tween
This commit is contained in:
@@ -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