| 12345678910111213141516171819202122232425262728 |
- import { _decorator, Component, Node, PhysicsSystem2D, EPhysics2DDrawFlags, Vec2, debug } from 'cc';
- const { ccclass, property } = _decorator;
- @ccclass('PhysicsManager')
- export class PhysicsManager extends Component {
- @property
- debugDraw: boolean = false;
- start() {
- // 启用物理系统
- PhysicsSystem2D.instance.enable = true;
-
- // 设置物理系统的重力为零(因为是2D平面游戏)
- PhysicsSystem2D.instance.gravity = new Vec2(0, 0);
-
- // 如果启用了调试绘制,显示碰撞体
- if (this.debugDraw) {
- PhysicsSystem2D.instance.debugDrawFlags =
- EPhysics2DDrawFlags.Aabb |
- EPhysics2DDrawFlags.Pair |
- EPhysics2DDrawFlags.CenterOfMass |
- EPhysics2DDrawFlags.Joint |
- EPhysics2DDrawFlags.Shape;
- } else {
- PhysicsSystem2D.instance.debugDrawFlags = EPhysics2DDrawFlags.None;
- }
- }
- }
|