@@ -128,7 +128,7 @@ private void onPhysicsEntityAdded(Entity entity) {
128
128
}
129
129
130
130
ChangeListener <Number > scaleChangeListener = (observable , oldValue , newValue ) -> {
131
- Body b = entity .getComponent (PhysicsComponent .class ).body ;
131
+ Body b = entity .getComponent (PhysicsComponent .class ).getBody () ;
132
132
133
133
if (b != null ) {
134
134
List <Fixture > fixtures = List .copyOf (b .getFixtures ());
@@ -290,14 +290,14 @@ private boolean needManualCheck(Entity e1, Entity e2) {
290
290
// if no physics -> check manually
291
291
292
292
BodyType type1 = e1 .getComponentOptional (PhysicsComponent .class )
293
- .map (p -> p .body .getType ())
293
+ .map (p -> p .getBody () .getType ())
294
294
.orElse (null );
295
295
296
296
if (type1 == null )
297
297
return true ;
298
298
299
299
BodyType type2 = e2 .getComponentOptional (PhysicsComponent .class )
300
- .map (p -> p .body .getType ())
300
+ .map (p -> p .getBody () .getType ())
301
301
.orElse (null );
302
302
303
303
if (type2 == null )
@@ -543,38 +543,38 @@ private void createBody(Entity e) {
543
543
PhysicsComponent physics = e .getComponent (PhysicsComponent .class );
544
544
physics .setWorld (this );
545
545
546
+ final BodyDef bodyDef = physics .getBodyDef ();
547
+
546
548
// if position is 0, 0 then probably not set, so set ourselves
547
- if (physics . bodyDef .getPosition ().x == 0 && physics . bodyDef .getPosition ().y == 0 ) {
548
- physics . bodyDef .getPosition ().set (toPoint (e .getCenter ()));
549
+ if (bodyDef .getPosition ().x == 0 && bodyDef .getPosition ().y == 0 ) {
550
+ bodyDef .getPosition ().set (toPoint (e .getCenter ()));
549
551
}
550
552
551
- if (physics . bodyDef .getAngle () == 0 ) {
552
- physics . bodyDef .setAngle ((float ) -Math .toRadians (e .getRotation ()));
553
+ if (bodyDef .getAngle () == 0 ) {
554
+ bodyDef .setAngle ((float ) -Math .toRadians (e .getRotation ()));
553
555
}
554
556
555
- physics .body = jboxWorld .createBody (physics .bodyDef );
556
-
557
+ physics .setBody (jboxWorld .createBody (bodyDef ));
557
558
createFixtures (e );
558
-
559
559
createSensors (e );
560
560
561
- physics .body .setEntity (e );
561
+ physics .getBody () .setEntity (e );
562
562
physics .onInitPhysics ();
563
563
}
564
564
565
565
private void createFixtures (Entity e ) {
566
566
BoundingBoxComponent bbox = e .getBoundingBoxComponent ();
567
567
PhysicsComponent physics = e .getComponent (PhysicsComponent .class );
568
568
569
- FixtureDef fd = physics .fixtureDef ;
569
+ FixtureDef fd = physics .getFixtureDef () ;
570
570
571
571
for (HitBox box : bbox .hitBoxesProperty ()) {
572
572
Shape b2Shape = createShape (box , e );
573
573
574
574
// we use definitions from user, but override shape
575
575
fd .setShape (b2Shape );
576
576
577
- Fixture fixture = physics .body .createFixture (fd );
577
+ Fixture fixture = physics .getBody () .createFixture (fd );
578
578
579
579
fixture .setHitBox (box );
580
580
}
@@ -595,13 +595,13 @@ private void createSensors(Entity e) {
595
595
.sensor (true )
596
596
.shape (polygonShape );
597
597
598
- Fixture f = physics .body .createFixture (fd );
598
+ Fixture f = physics .getBody () .createFixture (fd );
599
599
f .setHitBox (box );
600
600
});
601
601
}
602
602
603
603
private Shape createShape (HitBox box , Entity e ) {
604
- if (e .getComponent (PhysicsComponent .class ).body .getType () != BodyType .STATIC
604
+ if (e .getComponent (PhysicsComponent .class ).getBody () .getType () != BodyType .STATIC
605
605
&& box .getShape () instanceof ChainShapeData ) {
606
606
throw new IllegalArgumentException ("BoundingShape.chain() can only be used with BodyType.STATIC" );
607
607
}
@@ -623,7 +623,7 @@ void destroyFixture(Body body, HitBox box) {
623
623
* @param e physics entity
624
624
*/
625
625
private void destroyBody (Entity e ) {
626
- jboxWorld .destroyBody (e .getComponent (PhysicsComponent .class ).body );
626
+ jboxWorld .destroyBody (e .getComponent (PhysicsComponent .class ).getBody () );
627
627
}
628
628
629
629
private EdgeCallback raycastCallback = new EdgeCallback ();
@@ -747,8 +747,8 @@ public <T extends Joint> T addJoint(Entity e1, Entity e2, JointDef<T> def) {
747
747
var p1 = e1 .getComponent (PhysicsComponent .class );
748
748
var p2 = e2 .getComponent (PhysicsComponent .class );
749
749
750
- def .setBodyA (p1 .body );
751
- def .setBodyB (p2 .body );
750
+ def .setBodyA (p1 .getBody () );
751
+ def .setBodyB (p2 .getBody () );
752
752
753
753
return jboxWorld .createJoint (def );
754
754
}
0 commit comments