@@ -1112,6 +1112,62 @@ -(void)testApplyForce
1112
1112
[physics onExit ];
1113
1113
}
1114
1114
1115
+ -(void )testBodySleep
1116
+ {
1117
+ CCPhysicsNode *physics = [CCPhysicsNode node ];
1118
+ [physics onEnter ];
1119
+
1120
+ CCNode *staticNode = [CCNode node ];
1121
+ staticNode.physicsBody = [CCPhysicsBody bodyWithCircleOfRadius: 1 andCenter: CGPointZero];
1122
+ staticNode.physicsBody .type = CCPhysicsBodyTypeStatic;
1123
+ [physics addChild: staticNode];
1124
+
1125
+ CCNode *node = [CCNode node ];
1126
+ node.physicsBody = [CCPhysicsBody bodyWithCircleOfRadius: 1 andCenter: CGPointZero];
1127
+ node.physicsBody .mass = 5 ;
1128
+
1129
+ // Bodies default to being active.
1130
+ XCTAssertFalse (node.physicsBody .sleeping , @" " );
1131
+
1132
+ // Setting the sleeping property before adding to a scene should be ignored.
1133
+ node.physicsBody .sleeping = YES ;
1134
+ XCTAssertFalse (node.physicsBody .sleeping , @" " );
1135
+
1136
+ [physics addChild: node];
1137
+
1138
+ node.physicsBody .sleeping = YES ;
1139
+ XCTAssertTrue (node.physicsBody .sleeping , @" " );
1140
+
1141
+ node.physicsBody .sleeping = NO ;
1142
+ XCTAssertFalse (node.physicsBody .sleeping , @" " );
1143
+
1144
+ // Changing various flags should wake a body up.
1145
+ node.physicsBody .sleeping = YES ;
1146
+ XCTAssertTrue (node.physicsBody .sleeping , @" " );
1147
+ node.physicsBody .affectedByGravity = YES ;
1148
+ XCTAssertFalse (node.physicsBody .sleeping , @" " );
1149
+
1150
+ node.physicsBody .sleeping = YES ;
1151
+ XCTAssertTrue (node.physicsBody .sleeping , @" " );
1152
+ node.physicsBody .mass = 1.0 ;
1153
+ XCTAssertFalse (node.physicsBody .sleeping , @" " );
1154
+
1155
+ // Removing the node from the scene and re-adding it should wake up its body.
1156
+ node.physicsBody .sleeping = YES ;
1157
+ XCTAssertTrue (node.physicsBody .sleeping , @" " );
1158
+ [node removeFromParent ];
1159
+ [physics addChild: node];
1160
+ XCTAssertFalse (node.physicsBody .sleeping , @" " );
1161
+
1162
+ // Adding joints should wake up a body.
1163
+ node.physicsBody .sleeping = YES ;
1164
+ XCTAssertTrue (node.physicsBody .sleeping , @" " );
1165
+ [CCPhysicsJoint connectedMotorJointWithBodyA: node.physicsBody bodyB: staticNode.physicsBody rate: 1.0 ];
1166
+ XCTAssertFalse (node.physicsBody .sleeping , @" " );
1167
+
1168
+ [physics onExit ];
1169
+ }
1170
+
1115
1171
// TODO
1116
1172
// * Check that body and shape settings are preserved through multiple add/remove cycles and are actually applied to the cpBody.
1117
1173
// * Check that changing properties before and after adding to an active physics node updates the properties correctly.
0 commit comments