12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import { _decorator, Collider2D, Component, Contact2DType, IPhysics2DContact, log, Node, tween, UIOpacity, v3 } from 'cc';
- import { ColliderTag, Global } from '../Common/Global';
- import { GameManager } from '../Manager/GameManager';
- import { AudioManage } from '../Manager/AudioManage';
- const { ccclass, property } = _decorator;
- @ccclass('BallItem')
- export class BallItem extends Component {
- _index:number;
- start() {
- let collider = this.getComponent(Collider2D);
- if (collider) {
- collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
- }
- }
- // onBeginContact(selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
- // // 只在两个碰撞体开始接触时被调用一次
- // console.log('onBeginContact');
- // }
- //碰撞事件
- onBeginContact(self: Collider2D, other: Collider2D) {
- if (other.tag == ColliderTag.GouLanzi) {
- if (self.tag == ColliderTag.TargetBall) {
- GameManager.getInstance().showTips("太棒了")
- AudioManage.instance.playSound(Global.Audio_AddScore);
- tween(self.node).to(0.1, { scale: v3() }).call(() => {
- self.node.destroy();
- GameManager.getInstance().addScore(10);
- }).start();
- } else if (self.tag == ColliderTag.WriteBall) {
- GameManager.getInstance().showTips("请继续加油哦")
- AudioManage.instance.playSound(Global.Audio_MinusScore);
- tween(self.getComponent(UIOpacity)).to(0.1, { opacity: 0 }).to(0.1, { opacity: 255 }).to(0.1, { opacity: 0 }).call(() => {
- self.node.destroy();
- GameManager.getInstance().minusScore(10);
- }).start();
- // self.node.destroy();
- // GameManager.getInstance().minusScore(10);
- }
- }
- }
- update(deltaTime: number) {
- }
- }
|