ios - Sprite Kit didBeginContact 未在 body 和 edgeRect 之间调用
<p><p>我有一个游戏,我将 body 从屏幕上弹开。我想检测这些 body 何时与屏幕的边缘接触(仍然让 body 通过屏幕离开屏幕),我已经实现了一切,但它仍然无法正常工作..这是我的代码:</p >
<p>GameScene.h</p>
<pre><code> typedef NS_OPTIONS(uint32_t, FAPhysicsCategory) {
FAWallCategory = 1 << 0,
FABottomWallCategory = 1 << 1,
FAAnimalCategory = 1 << 2,
};
GameScene : SKScene <SKPhsyicsContactDelegate>
</code></pre>
<p>GameScene.m</p>
<pre><code>-(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 = ;
self.physicsBody.categoryBitMask = FAWallCategory;
self.physicsBody.contactTestBitMask = FAAnimalCategory;
self.physicsBody.collisionBitMask = 0;
}
-(void)launchBody {
SKSpriteNode* animalSprite = ];
animalSprite.position = CGPointMake(self.size.width/2, -animalSprite.size.height);
animalSprite.physicsBody = ;
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;
;
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>好吧,现在已经很晚了,我已经筋疲力尽了,我觉得自己像个白痴……我不见了:</p>
<pre><code>self.physicsWorld.contactDelegate = self;
</code></pre>
<h1>工具</h1></p>
<p style="font-size: 20px;">关于ios - Sprite Kit didBeginContact 未在 body 和 edgeRect 之间调用,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/27009249/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/27009249/
</a>
</p>
页:
[1]