1
我正在研究一種遊戲,它將觸摸檢測與圓形的skShapenodes合併在一起,並且無法找到檢查它們是否觸摸的好方法。代碼爲玩家級低於如何與skshapenode圈進行碰撞
-(void)SpawnPlayer
{
_player = [[SKShapeNode alloc] init];
CGMutablePathRef myPath = CGPathCreateMutable();
CGPathAddArc(myPath, NULL, 0,0, 15, 0, M_PI*2, YES);
_player.path = myPath;
_player.lineWidth = 1.0;
_player.fillColor = [SKColor whiteColor];
_player.strokeColor = [SKColor whiteColor];
_player.glowWidth = 0.5;
_location = CGPointMake(375, 400);
_player.position = CGPointMake(375, 400);
_player.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:0.5];
_player.physicsBody.dynamic = NO;
_player.physicsBody.categoryBitMask = playerCategory;
_player.physicsBody.contactTestBitMask = enemyCategory;
_player.physicsBody.collisionBitMask = 0;
[self addChild:_player];
}
敵人的代碼相似,不同之處在於它的掩碼和testbitmask切換。
AND的兩個聯繫位掩碼必須非零才能創建聯繫事件 - 如果您使用不同的聯繫位掩碼,它們將不會生成聯繫活動 – LearnCocos2D
對不起,我是一名學生,這是我第一年使用目標c,請您詳細說明一下嗎? – SamN