菜鸟教程小白 发表于 2022-12-12 12:49:20

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 &lt;&lt; 0,
FABottomWallCategory = 1 &lt;&lt; 1,
FAAnimalCategory = 1 &lt;&lt; 2,
};

GameScene : SKScene &lt;SKPhsyicsContactDelegate&gt;
</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 = @&#34;animalSprite&#34;;
    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]
查看完整版本: ios - Sprite Kit didBeginContact 未在 body 和 edgeRect 之间调用