나는 비트 마스크, CategoryBitMasks 및 CollisionBitMasks의 개념을 이해할 수 있다고 생각했지만 실제로는 그렇지 않습니다 .- 하지만 이유는 알지 못합니다. 충돌 감지를 위해 비트 마스크를 설정했습니다. 프레임에 카테고리 비트 마스크를 추가, 내가 (이 경우 택시를) 내 객체에 categoryBitMask를 추가하지만 택시는 단지 화면을 아래로 떨어 : -.?/SpriteKit 충돌 감지가 작동하지 않습니다
어떤 아이디어이 그런 이유
#import "MyScene.h"
#import "SKSpriteNode+DebugDraw.h"
// Define Bit Masks for Collision Detection
typedef NS_OPTIONS(uint32_t, CNPhysicsCategory) {
CNPhysicsCategoryEdge = 1 <<0,
CNPhysicsCategoryTaxi = 1 <<1,
};
@interface MyScene() <SKPhysicsContactDelegate>
@end
@implementation MyScene{
SKNode *_gameNode;
SKSpriteNode *_taxiNode;
}
-(instancetype)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
[self initializeScene];
}
return self;
}
-(void)initializeScene{
self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:self.frame];
self.physicsWorld.contactDelegate = self;
self.physicsBody.categoryBitMask = CNPhysicsCategoryEdge;
SKSpriteNode* bg = [SKSpriteNode spriteNodeWithImageNamed:@"background.png"];
bg.position = CGPointMake(self.size.width/2, self.size.height/2);
[self addChild: bg];
[self addTaxi];
_gameNode = [SKNode node];
[self addChild:_gameNode];
}
-(void)addTaxi{
_taxiNode = [SKSpriteNode spriteNodeWithImageNamed:@"taxi.png"];
_taxiNode.position = CGPointMake(self.size.width/2, self.size.height/2);
[self addChild:_taxiNode];
CGSize contactSize = CGSizeMake(_taxiNode.size.width, _taxiNode.size.height);
_taxiNode.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize: contactSize];
[_taxiNode attachDebugRectWithSize:contactSize];
_taxiNode.physicsBody.categoryBitMask = CNPhysicsCategoryTaxi;
}
** physicsBody를 초기화 한 후 taxiNode **를 추가하십시오 .Body – ZeMoon
다른 카테고리에 넣거나 똑같이 사용하거나 연락처 및 충돌 비트 마스크에 충돌해야하는 비트가 포함되어 있는지 확인하십시오. "세계"모양의 경우 비트 마스크를 그대로 두십시오. – LearnCocos2D
질문이 명확하지 않습니다. 충돌을 감지하거나 화면에서 떨어지는 물체에 문제가 있습니까? – sangony