This commit is contained in:
2024-07-30 10:55:31 +08:00
parent 76b400885c
commit d85ed9e6b6
13 changed files with 663 additions and 55 deletions

View File

@@ -28,37 +28,14 @@ export class MonsterViewComp extends CCComp {
timer: number = 0;
/** 视图层逻辑代码分离演示 */
start () {
// 注册单个碰撞体的回调函数
// console.log('MonsterViewComp start');
let collider = this.getComponent(Collider2D);
// console.log('Monster collider',collider);
if (collider) {
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
}
// 注册全局碰撞回调函数
if (PhysicsSystem2D.instance) {
// console.log('PhysicsSystem2D.instance');
PhysicsSystem2D.instance.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
}
}
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
// 只在两个碰撞体开始接触时被调用一次
// console.log('monster Contact,otherCollider',otherCollider);
this.speed = 0;
this.timer = 1;
switch (otherCollider.group) {
case BoxSet.HERO_SKILL:
// console.log('monster coolider hero skill');
break;
default:
break;
}
}
onLoad() {
this.as = this.getComponent(MonsterSpine);
console.log('this.ospeed:',this);
console.log('this.ent:',this);
}
update(dt: number){
@@ -72,7 +49,7 @@ export class MonsterViewComp extends CCComp {
if(this.node.position.x > -360){
this.move(dt);
}
if(this.node.position.x < -360){
if(this.node.position.x < -300){
smc.monsters_in = smc.monsters_in.filter(element => element.eid !== this.ent.eid);
this.node.destroy();
}