gpt4 book ai didi

ios - 如何使用 SKPhysicsJointFixed 连接两个 SKSpriteNode

转载 作者:行者123 更新时间:2023-11-29 12:43:23 26 4
gpt4 key购买 nike

当我尝试使用 SKPhysicsJointFixed 连接两个 SKSpriteNode 时,它​​们分开,就好像根本没有连接一样。我所做的一切似乎都不起作用。这是我的代码...

CGPoint position = CGPointMake(100, 100);
CGSize size = CGSizeMake(4, 64);

SKSpriteNode *node1 = [SKSpriteNode spriteNodeWithColor:[SKColor whiteColor] size:size];
node1.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:size];
node1.position = position;

SKSpriteNode *node2 = [SKSpriteNode spriteNodeWithColor:[SKColor whiteColor] size:size];
node2.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:size];
node2.position = position;

[scene addChild:node1];
[scene addChild:node2];

SKPhysicsJointFixed *joint = [SKPhysicsJointFixed jointWithBodyA:node1.physicsBody
bodyB:node2.physicsBody
anchor:CGPointMake(100, 100)];
[scene.physicsWorld addJoint:joint];

提前致谢。

最佳答案

这是我的工作代码....

CGPoint position = CGPointMake(100, 350);
CGPoint position2 = CGPointMake(100, 420);
CGSize size = CGSizeMake(4, 164);

SKSpriteNode *node1 = [SKSpriteNode spriteNodeWithColor:[SKColor whiteColor] size:size];
node1.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:size];
node1.position = position;

SKSpriteNode *node2 = [SKSpriteNode spriteNodeWithColor:[SKColor redColor] size:size];
node2.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:size];
node2.position = position2;

[scene addChild:node1];
[scene addChild:node2];

SKPhysicsJointFixed *joint = [SKPhysicsJointFixed jointWithBodyA:node1.physicsBody
bodyB:node2.physicsBody
anchor:CGPointMake(node1.position.x, node1.position.y-30)];

[scene.physicsWorld addJoint:joint];

关于ios - 如何使用 SKPhysicsJointFixed 连接两个 SKSpriteNode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24300696/

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