好的,所以我让OBJ成为一个落下的物体。 OBJ B就像一枚硬币......我想收集它。当交叉这两个对象时。 obj b影响obj a的下降速度/轨迹。
我正在使用它:
- (void)didBeginContact:(SKPhysicsContact *)contact
当“obj b”与“obj a”相交时,如何不影响“obj a”的下降速度或轨迹?
这是“obj a”:
ship = [SKSpriteNode spriteNodeWithImageNamed:@"theShip"];
ship.name=@"ship";
ship.anchorPoint=CGPointMake(0.5, 0.5);
ship.size=CGSizeMake(100, 50);
ship.position=CGPointMake(CGRectGetMidX(myWorld.frame), 0);
ship.physicsBody.dynamic = YES;
[SKPhysicsBody bodyWithCircleOfRadius:50];
ship.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:ship.frame.size.width * 0.5];
ship.physicsBody.allowsRotation=NO;
ship.physicsBody.categoryBitMask=shipCategory;
ship.physicsBody.contactTestBitMask = coinCategory | padCategory;
这是“obj b”:
Coin *node = [Coin node];
[node setPosition:position];
[node setName:@"node_coin"];
[node setCoinType:coinType];
SKSpriteNode *sprite;
if (coinType == COIN_NORMAL) {
sprite = [SKSpriteNode spriteNodeWithColor:[UIColor yellowColor] size:CGSizeMake(50, 50)];
} else if (coinType == COIN_DOUBLE){
sprite = [SKSpriteNode spriteNodeWithColor:[UIColor redColor] size:CGSizeMake(50, 50)];
}else if (coinType == COIN_TRIPLE){
sprite = [SKSpriteNode spriteNodeWithColor:[UIColor blueColor] size:CGSizeMake(50, 50)];
}
[node addChild:sprite];
node.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:sprite.size.width/2];
node.physicsBody.affectedByGravity=NO;
node.physicsBody.dynamic = NO;
node.physicsBody.categoryBitMask = coinCategory;
node.physicsBody.collisionBitMask = 0;
node.physicsBody.contactTestBitMask = 0;
我附上了一张图片,以便更清楚......
答案 0 :(得分:1)
TL; DR:collisionBitMask
默认设置为0xFFFFFFFF
(即所有位设置 - 感谢0x141E)。
这意味着 ObjA 将与设置了physicsBody
的每个对象发生冲突。
解决方案:将 ObjA 的collisionBitMask
设置为不同于0的内容。
collisionBitMask定义:
@property (nonatomic, assign) uint32_t collisionBitMask;