gpt4 book ai didi

ios Sprite 套件 bodyWithBodies 不工作

转载 作者:行者123 更新时间:2023-11-29 00:34:56 25 4
gpt4 key购买 nike

    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/

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