@safe-engine/cocos 1.5.8 → 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/box2d-wasm/ContactListener.js +9 -9
- package/dist/box2d-wasm/PhysicsComponent.d.ts +12 -14
- package/dist/box2d-wasm/PhysicsComponent.d.ts.map +1 -1
- package/dist/box2d-wasm/PhysicsComponent.js +0 -3
- package/dist/box2d-wasm/PhysicsSystem.d.ts +1 -0
- package/dist/box2d-wasm/PhysicsSystem.d.ts.map +1 -1
- package/dist/box2d-wasm/PhysicsSystem.js +22 -37
- package/dist/box2d-wasm/debugDraw.js +1 -1
- package/dist/box2d-wasm/index.d.ts +1 -1
- package/dist/box2d-wasm/index.d.ts.map +1 -1
- package/dist/box2d-wasm/index.js +4 -1
- package/dist/gworld/components/NodeComp.d.ts +1 -1
- package/dist/gworld/components/NodeComp.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RigidBody } from './PhysicsComponent';
|
|
2
2
|
export const makeContactListener = (world, metadata, box2D) => {
|
|
3
3
|
const { JSContactListener, getPointer, NULL } = box2D;
|
|
4
4
|
function getContactById(contact) {
|
|
@@ -22,8 +22,8 @@ export const makeContactListener = (world, metadata, box2D) => {
|
|
|
22
22
|
// listRemoveBody = []
|
|
23
23
|
// listRemoveShape = []
|
|
24
24
|
// })
|
|
25
|
-
const phys1 = ett1.getComponent(
|
|
26
|
-
const phys2 = ett2.getComponent(
|
|
25
|
+
const phys1 = ett1.getComponent(RigidBody);
|
|
26
|
+
const phys2 = ett2.getComponent(RigidBody);
|
|
27
27
|
// console.log('addPostStepCallback', ett1, phys1.props.onBeginContact, phys2.props)
|
|
28
28
|
if (phys1 && phys2) {
|
|
29
29
|
if (Object.prototype.hasOwnProperty.call(phys1.props, 'onBeginContact')) {
|
|
@@ -41,8 +41,8 @@ export const makeContactListener = (world, metadata, box2D) => {
|
|
|
41
41
|
const ett1 = metadata[getPointer(contact.GetFixtureA().GetBody())];
|
|
42
42
|
const ett2 = metadata[getPointer(contact.GetFixtureB().GetBody())];
|
|
43
43
|
// const event1 = ett1.getComponent(NodeComp)
|
|
44
|
-
const phys1 = ett1.getComponent(
|
|
45
|
-
const phys2 = ett2.getComponent(
|
|
44
|
+
const phys1 = ett1.getComponent(RigidBody);
|
|
45
|
+
const phys2 = ett2.getComponent(RigidBody);
|
|
46
46
|
// const event2 = ett2.getComponent(NodeComp)
|
|
47
47
|
if (phys1 && phys2) {
|
|
48
48
|
if (Object.prototype.hasOwnProperty.call(phys1.props, 'onEndContact')) {
|
|
@@ -60,8 +60,8 @@ export const makeContactListener = (world, metadata, box2D) => {
|
|
|
60
60
|
const ett1 = metadata[getPointer(contact.GetFixtureA().GetBody())];
|
|
61
61
|
const ett2 = metadata[getPointer(contact.GetFixtureB().GetBody())];
|
|
62
62
|
// const event1 = ett1.getComponent(NodeComp)
|
|
63
|
-
const phys1 = ett1.getComponent(
|
|
64
|
-
const phys2 = ett2.getComponent(
|
|
63
|
+
const phys1 = ett1.getComponent(RigidBody);
|
|
64
|
+
const phys2 = ett2.getComponent(RigidBody);
|
|
65
65
|
// const event2 = ett2.getComponent(NodeComp)
|
|
66
66
|
if (phys1 && phys2) {
|
|
67
67
|
if (Object.prototype.hasOwnProperty.call(phys1.props, 'onPostSolve')) {
|
|
@@ -79,8 +79,8 @@ export const makeContactListener = (world, metadata, box2D) => {
|
|
|
79
79
|
const ett1 = metadata[getPointer(contact.GetFixtureA().GetBody())];
|
|
80
80
|
const ett2 = metadata[getPointer(contact.GetFixtureB().GetBody())];
|
|
81
81
|
// const event1 = ett1.getComponent(NodeComp)
|
|
82
|
-
const phys1 = ett1.getComponent(
|
|
83
|
-
const phys2 = ett2.getComponent(
|
|
82
|
+
const phys1 = ett1.getComponent(RigidBody);
|
|
83
|
+
const phys2 = ett2.getComponent(RigidBody);
|
|
84
84
|
// const event2 = ett2.getComponent(NodeComp)
|
|
85
85
|
if (phys1 && phys2) {
|
|
86
86
|
if (Object.prototype.hasOwnProperty.call(phys1.props, 'onPostSolve')) {
|
|
@@ -8,37 +8,35 @@ interface RigidBodyProps {
|
|
|
8
8
|
restitution?: Float;
|
|
9
9
|
friction?: Float;
|
|
10
10
|
gravityScale?: Float;
|
|
11
|
+
isSensor?: boolean;
|
|
12
|
+
tag?: number;
|
|
13
|
+
onBeginContact?: (other: RigidBody) => void;
|
|
14
|
+
onEndContact?: (other: RigidBody) => void;
|
|
15
|
+
onPreSolve?: (other: RigidBody, impulse?: any) => void;
|
|
16
|
+
onPostSolve?: (other: RigidBody, oldManifold?: any) => void;
|
|
11
17
|
}
|
|
12
18
|
export declare class RigidBody extends NoRenderComponentX<RigidBodyProps> {
|
|
13
19
|
body: Box2D.b2Body;
|
|
14
|
-
}
|
|
15
|
-
interface ColliderPhysicsProps {
|
|
16
|
-
tag?: number;
|
|
17
|
-
offset?: Vec2;
|
|
18
|
-
onBeginContact?: (other: PhysicsCollider) => void;
|
|
19
|
-
onEndContact?: (other: PhysicsCollider) => void;
|
|
20
|
-
onPreSolve?: (other: PhysicsCollider, impulse?: any) => void;
|
|
21
|
-
onPostSolve?: (other: PhysicsCollider, oldManifold?: any) => void;
|
|
22
|
-
}
|
|
23
|
-
export declare class PhysicsCollider extends NoRenderComponentX<ColliderPhysicsProps & BaseComponentProps<PhysicsCollider>> {
|
|
24
|
-
enabled: boolean;
|
|
25
20
|
physicSprite: PhysicsSprite;
|
|
26
21
|
}
|
|
27
22
|
interface BoxColliderPhysicsProps {
|
|
28
23
|
width: number;
|
|
29
24
|
height: number;
|
|
25
|
+
offset?: [number, number];
|
|
30
26
|
}
|
|
31
|
-
export declare class PhysicsBoxCollider extends NoRenderComponentX<BoxColliderPhysicsProps & BaseComponentProps<
|
|
27
|
+
export declare class PhysicsBoxCollider extends NoRenderComponentX<BoxColliderPhysicsProps & BaseComponentProps<PhysicsBoxCollider>> {
|
|
32
28
|
}
|
|
33
29
|
interface CircleColliderPhysicsProps {
|
|
34
30
|
radius: number;
|
|
31
|
+
offset?: [number, number];
|
|
35
32
|
}
|
|
36
|
-
export declare class PhysicsCircleCollider extends NoRenderComponentX<CircleColliderPhysicsProps & BaseComponentProps<
|
|
33
|
+
export declare class PhysicsCircleCollider extends NoRenderComponentX<CircleColliderPhysicsProps & BaseComponentProps<PhysicsCircleCollider>> {
|
|
37
34
|
}
|
|
38
35
|
interface PolygonColliderPhysicsProps {
|
|
39
36
|
points: Array<Vec2> | [number, number][];
|
|
37
|
+
offset?: [number, number];
|
|
40
38
|
}
|
|
41
|
-
export declare class PhysicsPolygonCollider extends NoRenderComponentX<PolygonColliderPhysicsProps & BaseComponentProps<
|
|
39
|
+
export declare class PhysicsPolygonCollider extends NoRenderComponentX<PolygonColliderPhysicsProps & BaseComponentProps<PhysicsPolygonCollider>> {
|
|
42
40
|
}
|
|
43
41
|
export {};
|
|
44
42
|
//# sourceMappingURL=PhysicsComponent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PhysicsComponent.d.ts","sourceRoot":"","sources":["../../src/box2d-wasm/PhysicsComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE/C,UAAU,cAAc;IACtB,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAChB,OAAO,CAAC,EAAE,KAAK,CAAA;IACf,WAAW,CAAC,EAAE,KAAK,CAAA;IACnB,QAAQ,CAAC,EAAE,KAAK,CAAA;IAChB,YAAY,CAAC,EAAE,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"PhysicsComponent.d.ts","sourceRoot":"","sources":["../../src/box2d-was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ACD,UAAU,0BAA0B;IAClC,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC1B;AACD,qBAAa,qBAAsB,SAAQ,kBAAkB,CAAC,0BAA0B,GAAG,kBAAkB,CAAC,qBAAqB,CAAC,CAAC;CAAG;AACxI,UAAU,2BAA2B;IACnC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAA;IACxC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC1B;AACD,qBAAa,sBAAuB,SAAQ,kBAAkB,CAAC,2BAA2B,GAAG,kBAAkB,CAAC,sBAAsB,CAAC,CAAC;CAAG"}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { NoRenderComponentX } from '../gworld/core/decorator';
|
|
2
2
|
export class RigidBody extends NoRenderComponentX {
|
|
3
3
|
body;
|
|
4
|
-
}
|
|
5
|
-
export class PhysicsCollider extends NoRenderComponentX {
|
|
6
|
-
enabled = true;
|
|
7
4
|
physicSprite;
|
|
8
5
|
}
|
|
9
6
|
export class PhysicsBoxCollider extends NoRenderComponentX {
|
|
@@ -11,6 +11,7 @@ export declare class PhysicsSystem implements System {
|
|
|
11
11
|
listRemoveShape: Box2D.b2Shape[];
|
|
12
12
|
colliderMatrix: boolean[][];
|
|
13
13
|
graphics: cc.DrawNode;
|
|
14
|
+
addDebug(): void;
|
|
14
15
|
configure(event_manager: EventManager): void;
|
|
15
16
|
update(entities: EntityManager, events: EventManager, dt: number): void;
|
|
16
17
|
set enabled(val: any);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PhysicsSystem.d.ts","sourceRoot":"","sources":["../../src/box2d-wasm/PhysicsSystem.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAc,MAAM,EAAE,MAAM,YAAY,CAAA;AAQ5E,eA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C,MAAM,CAAC,QAAQ,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM;IAwBhE,IAAI,OAAO,CAAC,GAAG,KAAA,EAMd;CACF"}
|
|
@@ -3,7 +3,7 @@ import { EventTypes } from 'entityx-ts';
|
|
|
3
3
|
import { GameWorld, instantiate, NodeComp, Vec2 } from '..';
|
|
4
4
|
import { makeContactListener } from './ContactListener';
|
|
5
5
|
import { makeDebugDraw } from './debugDraw';
|
|
6
|
-
import { PhysicsBoxCollider, PhysicsCircleCollider,
|
|
6
|
+
import { PhysicsBoxCollider, PhysicsCircleCollider, PhysicsPolygonCollider, RigidBody } from './PhysicsComponent';
|
|
7
7
|
import { PhysicsSprite } from './PhysicsSprite';
|
|
8
8
|
export const DynamicBody = 2;
|
|
9
9
|
export const KinematicBody = 1;
|
|
@@ -36,20 +36,20 @@ export class PhysicsSystem {
|
|
|
36
36
|
listRemoveShape = [];
|
|
37
37
|
colliderMatrix = [[true]];
|
|
38
38
|
graphics;
|
|
39
|
+
addDebug() {
|
|
40
|
+
const debugDraw = makeDebugDraw(this.graphics, pixelsPerMeter, box2D);
|
|
41
|
+
this.world.SetDebugDraw(debugDraw);
|
|
42
|
+
}
|
|
39
43
|
configure(event_manager) {
|
|
40
44
|
const { b2BodyDef, b2FixtureDef, b2PolygonShape, b2CircleShape, b2Vec2, b2World, pointsToVec2Array, getPointer } = box2D;
|
|
41
45
|
const gravity = new b2Vec2(0, -10);
|
|
42
46
|
this.world = new b2World(gravity);
|
|
43
47
|
console.log('configure PhysicsSystem world', this.world);
|
|
44
|
-
// event_manager.world.physicsManager = this
|
|
45
48
|
const graphics = new cc.DrawNode();
|
|
46
49
|
this.graphics = graphics;
|
|
47
50
|
graphics.zIndex = 1000;
|
|
48
51
|
const scene = cc.director.getRunningScene();
|
|
49
52
|
scene.addChild(graphics);
|
|
50
|
-
const debugDraw = makeDebugDraw(graphics, pixelsPerMeter, box2D);
|
|
51
|
-
this.world.SetDebugDraw(debugDraw);
|
|
52
|
-
// event_manager.subscribe(ComponentAddedEvent(RigidBody), this);
|
|
53
53
|
event_manager.subscribe(EventTypes.ComponentAdded, PhysicsBoxCollider, ({ entity, component }) => {
|
|
54
54
|
console.log('ComponentAddedEvent PhysicsBoxCollider', component);
|
|
55
55
|
let rigidBody = entity.getComponent(RigidBody);
|
|
@@ -57,17 +57,12 @@ export class PhysicsSystem {
|
|
|
57
57
|
rigidBody = instantiate(RigidBody);
|
|
58
58
|
entity.assign(rigidBody);
|
|
59
59
|
}
|
|
60
|
-
let physicsCollide = entity.getComponent(PhysicsCollider);
|
|
61
|
-
if (!physicsCollide) {
|
|
62
|
-
physicsCollide = instantiate(PhysicsCollider);
|
|
63
|
-
entity.assign(physicsCollide);
|
|
64
|
-
}
|
|
65
60
|
const { type = StaticBody, gravityScale = 1, density = 1, friction = 0.5, restitution = 0.3 } = rigidBody.props;
|
|
66
61
|
const box = component;
|
|
67
62
|
const node = entity.getComponent(NodeComp);
|
|
68
|
-
const { width, height } = box.props;
|
|
69
|
-
const
|
|
70
|
-
const zero = new b2Vec2(
|
|
63
|
+
const { width, height, offset = [] } = box.props;
|
|
64
|
+
const [x = 0, y = 0] = offset;
|
|
65
|
+
const zero = new b2Vec2(0, 0);
|
|
71
66
|
const position = new b2Vec2(node.posX, node.posY);
|
|
72
67
|
const bd = new b2BodyDef();
|
|
73
68
|
bd.set_type(type);
|
|
@@ -79,7 +74,7 @@ export class PhysicsSystem {
|
|
|
79
74
|
// body.setMassData({ mass: 1 } as any)
|
|
80
75
|
const physicsNode = new PhysicsSprite(node.instance, body);
|
|
81
76
|
const square = new b2PolygonShape();
|
|
82
|
-
square.SetAsBox(width / 2, height / 2);
|
|
77
|
+
square.SetAsBox(width / 2, height / 2, new b2Vec2(x, y), 0);
|
|
83
78
|
const fixtureDef = new b2FixtureDef();
|
|
84
79
|
fixtureDef.set_shape(square);
|
|
85
80
|
fixtureDef.set_density(density);
|
|
@@ -91,8 +86,8 @@ export class PhysicsSystem {
|
|
|
91
86
|
body.SetAwake(true);
|
|
92
87
|
body.SetEnabled(true);
|
|
93
88
|
metadata[getPointer(body)] = node;
|
|
94
|
-
|
|
95
|
-
|
|
89
|
+
rigidBody.physicSprite = physicsNode;
|
|
90
|
+
rigidBody.node = node;
|
|
96
91
|
box.node = node;
|
|
97
92
|
});
|
|
98
93
|
event_manager.subscribe(EventTypes.ComponentAdded, PhysicsCircleCollider, ({ entity, component }) => {
|
|
@@ -102,16 +97,11 @@ export class PhysicsSystem {
|
|
|
102
97
|
rigidBody = instantiate(RigidBody);
|
|
103
98
|
entity.assign(rigidBody);
|
|
104
99
|
}
|
|
105
|
-
let physicsCollide = entity.getComponent(PhysicsCollider);
|
|
106
|
-
if (!physicsCollide) {
|
|
107
|
-
physicsCollide = instantiate(PhysicsCollider);
|
|
108
|
-
entity.assign(physicsCollide);
|
|
109
|
-
}
|
|
110
100
|
const { type = StaticBody, gravityScale = 1, density = 1, friction = 0.5, restitution = 0.3 } = rigidBody.props;
|
|
111
101
|
const node = entity.getComponent(NodeComp);
|
|
112
|
-
const { radius } = component.props;
|
|
113
|
-
const
|
|
114
|
-
const zero = new b2Vec2(
|
|
102
|
+
const { radius, offset = [] } = component.props;
|
|
103
|
+
const [x = 0, y = 0] = offset;
|
|
104
|
+
const zero = new b2Vec2(0, 0);
|
|
115
105
|
const position = new b2Vec2(node.posX, node.posY);
|
|
116
106
|
const bd = new b2BodyDef();
|
|
117
107
|
bd.set_type(type);
|
|
@@ -124,6 +114,7 @@ export class PhysicsSystem {
|
|
|
124
114
|
const physicsNode = new PhysicsSprite(node.instance, body);
|
|
125
115
|
const circleShape = new b2CircleShape();
|
|
126
116
|
circleShape.set_m_radius(radius);
|
|
117
|
+
circleShape.set_m_p(new b2Vec2(x, y));
|
|
127
118
|
const fixtureDef = new b2FixtureDef();
|
|
128
119
|
fixtureDef.set_shape(circleShape);
|
|
129
120
|
fixtureDef.set_density(density);
|
|
@@ -135,8 +126,8 @@ export class PhysicsSystem {
|
|
|
135
126
|
body.SetAwake(true);
|
|
136
127
|
body.SetEnabled(true);
|
|
137
128
|
metadata[getPointer(body)] = node;
|
|
138
|
-
|
|
139
|
-
|
|
129
|
+
rigidBody.physicSprite = physicsNode;
|
|
130
|
+
rigidBody.node = node;
|
|
140
131
|
component.node = node;
|
|
141
132
|
});
|
|
142
133
|
event_manager.subscribe(EventTypes.ComponentAdded, PhysicsPolygonCollider, ({ entity, component }) => {
|
|
@@ -146,16 +137,10 @@ export class PhysicsSystem {
|
|
|
146
137
|
rigidBody = instantiate(RigidBody);
|
|
147
138
|
entity.assign(rigidBody);
|
|
148
139
|
}
|
|
149
|
-
let physicsCollide = entity.getComponent(PhysicsCollider);
|
|
150
|
-
if (!physicsCollide) {
|
|
151
|
-
physicsCollide = instantiate(PhysicsCollider);
|
|
152
|
-
entity.assign(physicsCollide);
|
|
153
|
-
}
|
|
154
140
|
const { type = StaticBody, gravityScale = 1, density = 1, friction = 0.5, restitution = 0.3 } = rigidBody.props;
|
|
155
141
|
const node = entity.getComponent(NodeComp);
|
|
156
|
-
const { points } = component.props;
|
|
157
|
-
|
|
158
|
-
const { x = 0, y = 0 } = physicsCollide.props.offset || {};
|
|
142
|
+
const { points, offset = [] } = component.props;
|
|
143
|
+
const [x = 0, y = 0] = offset;
|
|
159
144
|
const zero = new b2Vec2(0, 0);
|
|
160
145
|
const position = new b2Vec2(node.posX, node.posY);
|
|
161
146
|
const { width, height } = node.getContentSize();
|
|
@@ -189,11 +174,11 @@ export class PhysicsSystem {
|
|
|
189
174
|
body.SetAwake(true);
|
|
190
175
|
body.SetEnabled(true);
|
|
191
176
|
metadata[getPointer(body)] = node;
|
|
192
|
-
|
|
193
|
-
|
|
177
|
+
rigidBody.physicSprite = physicsNode;
|
|
178
|
+
rigidBody.node = node;
|
|
194
179
|
component.node = node;
|
|
195
180
|
});
|
|
196
|
-
event_manager.subscribe(EventTypes.ComponentRemoved,
|
|
181
|
+
event_manager.subscribe(EventTypes.ComponentRemoved, RigidBody, ({ component }) => {
|
|
197
182
|
// console.log('ComponentRemovedEvent NodeComp', component)
|
|
198
183
|
if (component.physicSprite instanceof PhysicsSprite) {
|
|
199
184
|
const body = component.physicSprite.getBody();
|
|
@@ -69,7 +69,7 @@ export const makeDebugDraw = (graphics, pixelsPerMeter, box2D) => {
|
|
|
69
69
|
* @returns {void}
|
|
70
70
|
*/
|
|
71
71
|
const drawCircle = (center, radius, axis, fill) => {
|
|
72
|
-
graphics.drawCircle(center, radius, 0,
|
|
72
|
+
graphics.drawCircle(center, radius, 0, 32, true, 2, fill);
|
|
73
73
|
};
|
|
74
74
|
/**
|
|
75
75
|
* @param {Box2D.b2Vec2} vert1
|
|
@@ -2,5 +2,5 @@ import { GameWorld } from '..';
|
|
|
2
2
|
export * from './PhysicsComponent';
|
|
3
3
|
export * from './PhysicsSprite';
|
|
4
4
|
export * from './PhysicsSystem';
|
|
5
|
-
export declare function setupPhysics(world?: GameWorld): void;
|
|
5
|
+
export declare function setupPhysics(world?: GameWorld, isDebugDraw?: any): void;
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/box2d-wasm/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAA;AAG9B,cAAc,oBAAoB,CAAA;AAClC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAE/B,wBAAgB,YAAY,CAAC,KAAK,YAAqB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/box2d-wasm/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAA;AAG9B,cAAc,oBAAoB,CAAA;AAClC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAE/B,wBAAgB,YAAY,CAAC,KAAK,YAAqB,EAAE,WAAW,CAAC,KAAA,QAOpE"}
|
package/dist/box2d-wasm/index.js
CHANGED
|
@@ -3,8 +3,11 @@ import { PhysicsSystem } from './PhysicsSystem';
|
|
|
3
3
|
export * from './PhysicsComponent';
|
|
4
4
|
export * from './PhysicsSprite';
|
|
5
5
|
export * from './PhysicsSystem';
|
|
6
|
-
export function setupPhysics(world = GameWorld.Instance) {
|
|
6
|
+
export function setupPhysics(world = GameWorld.Instance, isDebugDraw) {
|
|
7
7
|
world.systems.add(PhysicsSystem);
|
|
8
8
|
world.systems.configureOnce(PhysicsSystem);
|
|
9
9
|
world.listUpdate.push(PhysicsSystem);
|
|
10
|
+
if (isDebugDraw) {
|
|
11
|
+
world.systems.get(PhysicsSystem).addDebug();
|
|
12
|
+
}
|
|
10
13
|
}
|
|
@@ -14,7 +14,7 @@ export declare class NodeComp<C extends cc.Node = cc.Node> {
|
|
|
14
14
|
get uuid(): number;
|
|
15
15
|
get position(): Readonly<Vec2>;
|
|
16
16
|
set position(val: Vec2);
|
|
17
|
-
set xy(val:
|
|
17
|
+
set xy(val: [number, number]);
|
|
18
18
|
get posX(): number;
|
|
19
19
|
set posX(val: number);
|
|
20
20
|
get posY(): number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeComp.d.ts","sourceRoot":"","sources":["../../../src/gworld/components/NodeComp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAGhD,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AACtC,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAGtE,MAAM,MAAM,iBAAiB,GAAG,CAAC,GAAG,IAAI,OAAA,KAAK,IAAI,CAAA;AACjD,qBAAa,QAAQ,CAAC,CAAC,SAAS,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,IAAI;IAC/C,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,CA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