feature/ads-smart-display
tiendat3699 2024-07-10 16:16:55 +07:00
parent 39f6cd6a2c
commit 95259b25d6
1 changed files with 5 additions and 7 deletions

View File

@ -40,12 +40,10 @@ export class ScoreObject extends Component implements IPoolable {
private _originColor: Color; private _originColor: Color;
private _isHit = false; private _isHit = false;
private _colliderEnabled: boolean = true;
protected onLoad(): void { protected onLoad(): void {
this._collider.on(Contact2DType.BEGIN_CONTACT, this.onContactBegin, this); this._collider.on(Contact2DType.BEGIN_CONTACT, this.onContactBegin, this);
this._originColor = this._sprite.color.clone(); this._originColor = this._sprite.color.clone();
this._colliderEnabled = false; this._collider.enabled = false;
} }
protected update(dt: number): void { protected update(dt: number): void {
@ -68,9 +66,9 @@ export class ScoreObject extends Component implements IPoolable {
} }
private async onContactBegin(selfCollider: Collider2D, otherCollider: Collider2D) { private async onContactBegin(selfCollider: Collider2D, otherCollider: Collider2D) {
if (!this._colliderEnabled) return; if (!this._collider.enabled) return;
if (this._isHit) return; if (this._isHit) return;
this._colliderEnabled = false; this._collider.enabled = false;
if (this._hitSound) AudioManager.playSfx(this._hitSound); if (this._hitSound) AudioManager.playSfx(this._hitSound);
// let center = this.node.getWorldPosition(); // let center = this.node.getWorldPosition();
// let other = otherCollider.node.getWorldPosition(); // let other = otherCollider.node.getWorldPosition();
@ -91,12 +89,12 @@ export class ScoreObject extends Component implements IPoolable {
public async onGet() { public async onGet() {
this._animation.play(this._animation.clips[0].name); this._animation.play(this._animation.clips[0].name);
await Utils.delay(this._animation.clips[0].duration); await Utils.delay(this._animation.clips[0].duration);
this._colliderEnabled = true; this._collider.enabled = true;
} }
public onRelease() { public onRelease() {
this._isHit = false; this._isHit = false;
this._colliderEnabled = false; this._collider.enabled = false;
this.node.angle = 0; this.node.angle = 0;
this.node.setScale(Vec3.ONE); this.node.setScale(Vec3.ONE);
this._sprite.color = this._originColor; this._sprite.color = this._originColor;