gpt4 book ai didi

ios - Sprite Kit didBeginContact 未在 body 和 edgeRect 之间调用

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:02:47 24 4
gpt4 key购买 nike

我有一个游戏,我可以将 body 从屏幕上弹开。我想检测这些物体何时接触到屏幕的边缘(仍然让物体穿过屏幕)并且我已经实现了所有内容但仍然无法正常工作..这是我的代码:

游戏场景.h

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

GameScene : SKScene <SKPhsyicsContactDelegate>

GameScene.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];
}

最佳答案

好吧,已经很晚了,我精疲力尽,我觉得自己像个白痴..我不见了:

self.physicsWorld.contactDelegate = self;

工具

关于ios - Sprite Kit didBeginContact 未在 body 和 edgeRect 之间调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27009249/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com