cocoscreator 3.8.2 碰撞2d无效 大bug 引擎

这种模式 碰撞无效image 鼠标滑动黑色方块碰撞 白色方块 没反应

import { Contact2DType } from ‘cc’;

import { Collider2D, IPhysics2DContact } from ‘cc’;

import { BoxCollider2D } from ‘cc’;

import { _decorator, Component, Node } from ‘cc’;

import { EventTriggerListener } from ‘…/Script/Framework/Effect/EventTriggerListener’;

import { Vec3 } from ‘cc’;

import { v3 } from ‘cc’;

import { PhysicsSystem2D } from ‘cc’;

const { ccclass, property } = _decorator;

@ccclass(‘testPengZhuang’)

export class testPengZhuang extends Component {

@property(Node)

public objA:Node | null = null;

@property(Node)

public objB:Node | null = null;

start() {

    PhysicsSystem2D.instance.enable = true;

    this. bindEvent();

}

bindEvent():void{

    let collider = this.objA.getComponent(BoxCollider2D);

    collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);

    collider.on(Contact2DType.END_CONTACT, this.onEndContact, this);

    let collider_1 = this.objB.getComponent(BoxCollider2D);

    collider_1.on(Contact2DType.BEGIN_CONTACT, this.onBeginContactB, this);

    collider_1.on(Contact2DType.END_CONTACT, this.onEndContactB, this);

    EventTriggerListener.Get(this.objB,this).onDown = this.onDownB;

    EventTriggerListener.Get(this.objB,this).onMove = this.onMoveB;

    EventTriggerListener.Get(this.objB,this).onUp = this.onUpB;

}

onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {

    // 只在两个碰撞体开始接触时被调用一次

    console.log('onBeginContact');

}

onEndContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {

    // 只在两个碰撞体结束接触时被调用一次

    console.log('onEndContact');

}

onBeginContactB (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {

    // 只在两个碰撞体开始接触时被调用一次

    console.log('onBeginContact');

}

onEndContactB (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {

    // 只在两个碰撞体结束接触时被调用一次

    console.log('onEndContact');

}

isClick:boolean =false;

lastPos:Vec3 = Vec3.ZERO;

onDownB(obj:Node,p:Vec3):void{

    this.lastPos =v3(p.x,p.y,0);

    this.isClick =true;

   // console.error("onDownB this.lastPos"+p+"   "+this.lastPos);

}

onMoveB(obj:Node,p:Vec3):void{

  //  console.error("onMoveB this.lastPos"+p+"   "+this.lastPos);

   if(!this.isClick)

        return;

    if(this.lastPos.x==0)

        return;

    let dt:Vec3 =v3(p.x-this.lastPos.x,p.y-this.lastPos.y,0);

   // console.error(dt+"  "+p+"   "+this.lastPos);

    this.objB.position = v3(this.objB.position.x+dt.x,this.objB.position.y+dt.y,0);

    this.lastPos =v3(p.x,p.y,0);

}

onUpB(obj:Node,p:Vec3):void{

    this.isClick =false;

    this.lastPos =v3(p.x,p.y,0);

}

update(deltaTime: number) {

   

}

}
测试代码如上

内置的可以

没勾选上碰撞回调的那个吧

上述在2DPhysics System 内置的 Build In 什么设置不用动 就可以运行 但是在 Box2D Based 2D Physics System 下不行