碰撞
This commit is contained in:
@@ -12,6 +12,7 @@ import { MonsterSpine } from "./MonsterSpine";
|
||||
import { Monster } from "./Monster";
|
||||
import { MonsterModelComp } from "./MonsterModelComp";
|
||||
import { BoxSet } from "../common/config/BoxSet";
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@@ -41,7 +42,7 @@ export class MonsterViewComp extends CCComp {
|
||||
}
|
||||
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
// 只在两个碰撞体开始接触时被调用一次
|
||||
// console.log('monster Contact,selfCollider',selfCollider);
|
||||
// console.log('monster Contact,otherCollider',otherCollider);
|
||||
|
||||
switch (otherCollider.group) {
|
||||
case BoxSet.HERO:
|
||||
@@ -57,12 +58,32 @@ export class MonsterViewComp extends CCComp {
|
||||
|
||||
onLoad() {
|
||||
this.as = this.getComponent(MonsterSpine);
|
||||
|
||||
|
||||
}
|
||||
|
||||
update(dt: number){
|
||||
if(this.node.position.x > -360){
|
||||
this.move(dt);
|
||||
}
|
||||
if(this.node.position.x < -360){
|
||||
smc.monsters_in = smc.monsters_in.filter(element => element.eid !== this.ent.eid);
|
||||
this.node.destroy();
|
||||
}
|
||||
this.update_pos();
|
||||
|
||||
}
|
||||
move(dt: number){
|
||||
this.node.setPosition(this.node.position.x-dt*this.speed, this.node.position.y, this.node.position.z);
|
||||
}
|
||||
|
||||
update_pos(){
|
||||
smc.monsters_in.forEach(element => {
|
||||
if(element.eid == this.ent.eid){
|
||||
element.pos_x = this.node.position.x;
|
||||
}
|
||||
});
|
||||
// console.log('smc.monsters_in',smc.monsters_in);
|
||||
}
|
||||
reset() {
|
||||
this.node.destroy();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user