2

我有一个游戏,我正在将身体从屏幕上弹开。我想检测这些身体何时与屏幕的边缘接触(仍然让身体通过屏幕离开屏幕),我已经实现了一切,但它仍然无法正常工作..这是我的代码:

游戏场景.h

 typedef NS_OPTIONS(uint32_t, FAPhysicsCategory) {
FAWallCategory = 1 << 0,
FABottomWallCategory = 1 << 1,
FAAnimalCategory = 1 << 2,
};

 GameScene : SKScene <SKPhsyicsContactDelegate>

游戏场景.m

-(void)setupWorldPhysics
{
// Set world gravity
self.physicsWorld.gravity = CGVectorMake(0.0, -5.0);

float bottomOffset = 400.0;
CGRect newFrame = CGRectMake(0, -bottomOffset, self.frame.size.width, self.frame.size.height + bottomOffset);
self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:newFrame];
self.physicsBody.categoryBitMask = FAWallCategory;
self.physicsBody.contactTestBitMask = FAAnimalCategory;
self.physicsBody.collisionBitMask = 0;
}

 -(void)launchBody {
     SKSpriteNode* animalSprite = [SKSpriteNode spriteNodeWithImageNamed:[animalImagesArray objectAtIndex:animalChoice]];
    animalSprite.position = CGPointMake(self.size.width/2, -animalSprite.size.height);
    animalSprite.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:25];
    animalSprite.physicsBody.dynamic = YES;
    animalSprite.physicsBody.allowsRotation = YES;
    animalSprite.name = @"animalSprite";
    animalSprite.physicsBody.categoryBitMask = FAAnimalCategory;
    animalSprite.physicsBody.contactTestBitMask = FAWallCategory;
    animalSprite.physicsBody.collisionBitMask = 0;
    animalSprite.physicsBody.usesPreciseCollisionDetection = YES;
    [self addChild:animalSprite];
 }
4

1 回答 1

2

好吧,太晚了,我筋疲力尽,我觉得自己像个白痴……我不见了:

self.physicsWorld.contactDelegate = self;

工具

于 2014-11-19T05:34:43.887 回答