gpt4 book ai didi

ios - bodyWithBodies SKPhysics body

转载 作者:行者123 更新时间:2023-11-29 12:47:35 25 4
gpt4 key购买 nike

Apple 的文档在解释如何有效地实现此类方法时含糊不清

+ (SKPhysicsBody *)bodyWithBodies:(NSArray *)bodies; //the error that I'm getting is 2014-04-23 23:25:21.518 Space Monkey[3398:60b] -[SKSpriteNode _shapes]: unrecognized selector sent to instance 0x15d79c50

2014-04-23 23:25:21.520 Space Monkey[3398:60b] * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[SKSpriteNode _shapes]:无法识别的选择器发送到实例 0x15d79c50”* 首先抛出调用栈:(0x2d92ef03 0x380c3ce7 0x2d932837 0x2d93112f...它抛出了一个异常(exception),我几乎到处都进行了研究,但没有运气。关于这里的同一问题还有另一个问题,但是这些建议似乎根本不起作用。我已经提供了代码,以便有人能够阐明一些问题,并希望能指导我正确的方向......这是代码

-(NSMutableArray *)platformBars
{
NSMutableArray *array =[[NSMutableArray alloc]init];
//_spriteNode declared in the interface as an instance variable
_spriteNode=[SKSpriteNode node];
for (int i =0; i<5; i++)
{
_spriteNode= [SKSpriteNode spriteNodeWithImageNamed:@"Water Block"];
_spriteNode.physicsBody.mass = 10.0f;
_spriteNode.physicsBody.density = _spriteNode.size.height;
_spriteNode.position = CGPointMake(x , _spriteNode.position.y);
x=x+40;
[array addObject:_spriteNode];
}
return array;
}

-(PlatformNode *)createPlatformsAtPosition:(CGPoint)position
{
NSArray *arrays = [self platformBars];
PlatformNode *node =[PlatformNode node];
node.physicsBody = [SKPhysicsBody bodyWithBodies:arrays];
for (SKSpriteNode *sknode in arrays)
{
[node addChild:sknode];
}
node.position=position;
node.name =@"platform";
node.physicsBody.affectedByGravity = NO;
NSLog(@"bodyofSize %f",[node calculateAccumulatedFrame].size.width);
return node;
}

-(PlatformNode *)createPlatformsAtPosition:(CGPoint)position is called in the
-(void)didMoveToView:(SKView *)view body of the function.

我希望我包含了足够的细节和我的代码片段,希望有人能帮助我和其他人。先感谢您。

最佳答案

应该是

NSArray *arrays = [[self platformBars] copy];

代替

NSArray *arrays = [self platformBars];

因为[self platformBars]是可变数组而arrays是不可变的。
编辑
而且,数组中的顺便说一句是 SKSpriteNode,而不是物理体。所以

node.physicsBody = [SKPhysicsBody bodyWithBodies:arrays];

应该是

NSMutableArray *mArray=[NSMutableArray new];
for (SKSpriteNode *anySpriteNode in arrays){
[mArray addObject:anySpriteNode.physicsBody];
}
node.physicsBody = [SKPhysicsBody bodyWithBodies:mArray.copy];

关于ios - bodyWithBodies SKPhysics body ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23260219/

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