12
12
#import " CCPhysics+ObjectiveChipmunk.h"
13
13
14
14
15
- @interface CCPhysicsTests : XCTestCase
15
+ @interface CCPhysicsTests : XCTestCase <CCPhysicsCollisionDelegate>
16
16
17
17
@end
18
18
@@ -378,6 +378,8 @@ -(void)testDynamicAnchorPoint
378
378
379
379
node.rotation = 90 ;
380
380
XCTAssert (ccpDistance (node.position , CGPointZero) == 0.0 , @" " );
381
+
382
+ [physicsNode onExit ];
381
383
}
382
384
383
385
-(void )testStaticAnchorPoint
@@ -399,6 +401,8 @@ -(void)testStaticAnchorPoint
399
401
400
402
node.rotation = 90 ;
401
403
XCTAssert (ccpDistance (node.position , CGPointZero) == 0.0 , @" " );
404
+
405
+ [physicsNode onExit ];
402
406
}
403
407
404
408
-(void )testCollisionGroups
@@ -428,6 +432,8 @@ -(void)testCollisionGroups
428
432
// Both nodes should be at (0, 0)
429
433
XCTAssertTrue (CGPointEqualToPoint (node1.position , CGPointZero) , @" " );
430
434
XCTAssertTrue (CGPointEqualToPoint (node2.position , CGPointZero) , @" " );
435
+
436
+ [physicsNode onExit ];
431
437
}
432
438
433
439
-(void )testAffectedByGravity
@@ -461,6 +467,8 @@ -(void)testAffectedByGravity
461
467
462
468
// Node2 should stay at (0, 0)
463
469
XCTAssertTrue (node2.position .y == 0.0 , @" " );
470
+
471
+ [physicsNode onExit ];
464
472
}
465
473
466
474
-(void )testAllowsRotation
@@ -542,6 +550,8 @@ -(void)testAllowsRotation
542
550
543
551
XCTAssert (node.physicsBody .body .moment < INFINITY, @" " );
544
552
}
553
+
554
+ [physicsNode onExit ];
545
555
}
546
556
547
557
-(void )testBodyType
@@ -671,6 +681,50 @@ -(void)testBreakingJoints
671
681
XCTAssert (!joint2.valid , @" " );
672
682
XCTAssert (joint3.valid , @" " );
673
683
XCTAssert (joint4.valid , @" " );
684
+
685
+ [physics onExit ];
686
+ }
687
+
688
+ -(BOOL )ccPhysicsCollisionBegin : (CCPhysicsCollisionPair *)pair theStaticOne : (CCNode *)nodeA theDynamicOne : (CCNode *)nodeB
689
+ {
690
+ nodeB.physicsBody .type = CCPhysicsBodyTypeStatic;
691
+
692
+ // TODO not sure if we should hide the deferred nature or not... Hrm.
693
+ XCTAssertEqual (nodeB.physicsBody .type , CCPhysicsBodyTypeDynamic, @" " );
694
+
695
+ return FALSE ;
696
+ }
697
+
698
+ -(void )testBodyTypeCollisions
699
+ {
700
+ CCPhysicsNode *physicsNode = [CCPhysicsNode node ];
701
+ physicsNode.collisionDelegate = self;
702
+ physicsNode.gravity = ccp (0 , -100 );
703
+
704
+ CCNode *node1 = [CCNode node ];
705
+ node1.physicsBody = [CCPhysicsBody bodyWithCircleOfRadius: 1.0 andCenter: CGPointZero];
706
+ node1.physicsBody .type = CCPhysicsBodyTypeStatic;
707
+ node1.physicsBody .collisionType = @" theStaticOne" ;
708
+ [physicsNode addChild: node1];
709
+
710
+ CCNode *node2 = [CCNode node ];
711
+ node2.position = ccp (0 , 10 );
712
+ node2.physicsBody = [CCPhysicsBody bodyWithCircleOfRadius: 1.0 andCenter: CGPointZero];
713
+ node2.physicsBody .type = CCPhysicsBodyTypeDynamic;
714
+ node2.physicsBody .collisionType = @" theDynamicOne" ;
715
+ [physicsNode addChild: node2];
716
+
717
+ // Force entering the scene to set up the physics objects.
718
+ [physicsNode onEnter ];
719
+
720
+ // Step the physics for a while.
721
+ for (int i=0 ; i<100 ; i++){
722
+ [physicsNode fixedUpdate: 1.0 /100.0 ];
723
+ }
724
+
725
+ XCTAssertEqual (node2.physicsBody .type , CCPhysicsBodyTypeStatic, @" " );
726
+
727
+ [physicsNode onExit ];
674
728
}
675
729
676
730
// TODO
0 commit comments