【发布时间】:2014-02-28 19:51:49
【问题描述】:
我也有同样的问题:SKSpriteKit, detect non-transparency parts
我的帖子从那里被删除。我不知道为什么,在其他论坛,这是一个重复的帖子! 但是,好吧,如果你喜欢的话。可怜的丹尼仍然没有答案!
好吧,问题又来了: 有两个带有透明区域的 png 文件。就像danny huang的帖子一样。 如果它们碰撞“-(void)didBeginContact:(SKPhysicsContact *)contact”方法就会触发。 但我们要寻找的是它们只是与图像的不透明区域发生碰撞。
下面是一段小代码:
...
SKTexture *nyanTexture1 = [SKTexture textureWithImageNamed:@"test.png"];
nyanTexture1.filteringMode = SKTextureFilteringNearest;
nyan = [SKSpriteNode spriteNodeWithTexture:nyanTexture1];
nyan.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:nyan.size.height / 2];
nyan.physicsBody.dynamic = YES;
nyan.physicsBody.allowsRotation = NO;
...
nyan.physicsBody.categoryBitMask = nyanKategorie;
nyan.physicsBody.collisionBitMask = worldKategorie | tunnelKategorie;
nyan.physicsBody.contactTestBitMask = worldKategorie | tunnelKategorie;
...
WasserFallTexture1 = [SKTexture textureWithImageNamed:@"Wasserstrahl1.png"];
SKSpriteNode* tunnel1 = [SKSpriteNode spriteNodeWithTexture:WasserFallTexture1];
tunnel1.position = CGPointMake( 0, y );
tunnel1.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:tunnel1.size];
tunnel1.physicsBody.dynamic = NO;
tunnel1.physicsBody.categoryBitMask = tunnelKategorie;
tunnel1.physicsBody.contactTestBitMask = nyanKategorie;
...
[tunnel addChild:tunnel1];
如果没有 Spritekit 的出色引擎,我也可以做到这一点。我也实现了它,但我想知道一种使用 SpriteKit 引擎的方法。 我知道我可以更改“SKPhysicsBody”类型和区域,但我正在寻找一个可以捕捉两个 png 文件非透明区域之间碰撞的解决方案。
谢谢, 山姆
【问题讨论】: