Skip to content

Commit 767548e

Browse files
committed
Fixing a couple of CCPhysicsShape.collisionType bugs.
Former-commit-id: 7b1f352
1 parent 2f12530 commit 767548e

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

UnitTests/CCPhysicsTests.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,4 +605,8 @@ -(void)testBreakingJoints
605605
XCTAssert(joint4.valid, @"");
606606
}
607607

608+
// TODO
609+
// * Check that body and shape settings are preserved through multiple add/remove cycles and are actually applied to the cpBody.
610+
// * Check that changing properties before and after adding to an active physics node updates the properties correctly.
611+
608612
@end

cocos2d/CCPhysicsShape.m

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,17 @@ -(void)setCollisionGroup:(id)collisionGroup {
135135
}
136136

137137
// TODO these need a reference to the space to intern the strings
138-
// Needs to be deferred?
139138
-(NSString *)collisionType {return _collisionType;}
140-
-(void)setCollisionType:(NSString *)collisionType {_collisionType = [collisionType copy];}
139+
-(void)setCollisionType:(NSString *)collisionType
140+
{
141+
CCPhysicsNode *physics = self.physicsNode;
142+
if(physics){
143+
_collisionType = [physics internString:collisionType];
144+
self.shape.collisionType = _collisionType;
145+
} else {
146+
_collisionType = [collisionType copy];
147+
}
148+
}
141149

142150
-(NSArray *)collisionCategories {
143151
if(_collisionCategories){
@@ -207,7 +215,7 @@ -(void)willAddToPhysicsNode:(CCPhysicsNode *)physics nonRigidTransform:(cpTransf
207215
// nil the array references to save on memory.
208216
// They will rarely be read back and we can easily reconstruct the array.
209217
_collisionCategories = nil;
210-
_collisionType = nil;
218+
_collisionMask = nil;
211219

212220
[self rescaleShape:transform];
213221
}

0 commit comments

Comments
 (0)