碰撞
This commit is contained in:
@@ -5,11 +5,12 @@
|
||||
* @LastEditTime: 2022-08-17 12:36:18
|
||||
*/
|
||||
|
||||
import { Vec3, _decorator ,Collider2D,Contact2DType,PhysicsSystem2D,IPhysics2DContact} from "cc";
|
||||
import { Vec3, v3,_decorator ,Collider2D,Contact2DType,PhysicsSystem2D,IPhysics2DContact,EPhysics2DDrawFlags} from "cc";
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
||||
import { HeroSpine } from "./HeroSpine";
|
||||
import {BoxSet} from "../common/config/BoxSet"
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/** 角色显示组件 */
|
||||
@@ -19,14 +20,15 @@ export class HeroViewComp extends CCComp {
|
||||
/** 角色动画 */
|
||||
as: HeroSpine = null!;
|
||||
/** 角色控制器 */
|
||||
|
||||
speed: number = 100;
|
||||
Tpos: Vec3 = v3(0,-60,0);
|
||||
|
||||
start () {
|
||||
// 注册单个碰撞体的回调函数
|
||||
// console.log('MonsterViewComp start');
|
||||
let collider = this.getComponent(Collider2D);
|
||||
// console.log('hero collider',collider);
|
||||
if (collider) {
|
||||
// console.log('hero collider',collider);
|
||||
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
|
||||
}
|
||||
|
||||
@@ -58,7 +60,29 @@ export class HeroViewComp extends CCComp {
|
||||
|
||||
}
|
||||
|
||||
|
||||
update(dt: number){
|
||||
if(this.node.position.x < 360){
|
||||
this.move(dt);
|
||||
|
||||
}
|
||||
if(this.node.position.x > 360){
|
||||
smc.heros_in = smc.heros_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.heros_in.forEach(element => {
|
||||
if(element.eid == this.ent.eid){
|
||||
element.pos_x = this.node.position.x;
|
||||
}
|
||||
});
|
||||
// console.log('smc.heros_in',smc.heros_in);
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.node.destroy();
|
||||
|
||||
Reference in New Issue
Block a user