- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
SKSpriteNode * test = [[SKSpriteNode alloc] initWithColor:[UIColor redColor] size:CGSizeMake(100, 100)];
[self addChild:test];
[test setPosition:CGPointMake(300, 300)];
// bottom
CGSize textureSize = CGSizeMake(100, 100);
SKPhysicsBody *physicsBottom = [SKPhysicsBody bodyWithRectangleOfSize:textureSize];
physicsBottom.categoryBitMask = ColliderBottom;
physicsBottom.contactTestBitMask = ColliderBottom | ColliderObstacle;
// working...
// test.physicsBody = physicsBottom;
// not working... this line is problem.
test.physicsBody = [SKPhysicsBody bodyWithBodies:@[physicsBottom]];
didEndContact 无法通过此代码工作。
test.physicsBody = [SKPhysicsBody bodyWithBodies:@[physicsBottom]];
有什么问题吗???
typedef enum {
ColliderObstacle = 1 << 0,
ColliderCharacter = 1 << 2,
ColliderLeft = 1 << 3,
ColliderRight = 1 << 4,
ColliderBottom = 1 << 5,}ColliderType;
//不工作...这一行...我不明白。为什么 didEndContact 事件不起作用??????
最佳答案
我尝试了在项目中设置physicalsBody
的方法,但无法重现您的问题。然而,通过比较你和我的代码,我认为你的问题是你创建了一个 physicsBody
并将它设置为你创建的每个“碰撞器”,这与复制问题有关。也许可以通过添加 copy
方法来解决这个问题:
renderComponent.node.physicsBody = [SKPhysicsBody bodyWithBodies:@[[physicsComponentBottom.physicsBody copy]
]];
我读了documentation后来发现该方法的限制,它只支持volume-based
physicsBody。这可能是你的问题。
Sprite Kit supports two kinds of physics bodies, volume-based bodies and edge-based bodies. When you create a physics body, its kind, size, and shape are determined by the constructor method you call. An edge-based body does not have mass or volume and is unaffected by forces or impulses in the system. Edge-based bodies are used to represent volume-less boundaries or hollow spaces in your physics simulation. In contrast, volume-based bodies are used to represent objects with mass and volume.
关于ios Sprite 套件 bodyWithBodies 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40839623/
Apple 的文档在解释如何有效地实现此类方法时含糊不清 + (SKPhysicsBody *)bodyWithBodies:(NSArray *)bodies; //the error that I
如何创建SKPhysicsBody bodyWithBodies? 我是新手,我试过了,但它不会出现在模拟器上。有人可以举个例子吗?这是我的部分代码: Bike = [SKSpriteNode nod
我希望我的 spritenode 有多个 physicbodies。我使用了 bodyWithbodies 并添加了 phyisicbodies。但是没有检测到碰撞。 下面是创建 spritenode
SKSpriteNode * test = [[SKSpriteNode alloc] initWithColor:[UIColor redColor] size:CGSizeMake(100, 10
我是一名优秀的程序员,十分优秀!