【发布时间】:2014-04-24 05:01:19
【问题描述】:
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... 它抛出了一个异常,我几乎到处都在研究,但没有运气。这里有关于同一问题的另一个问题,但是这些建议似乎根本不起作用。我已经提供了代码,以便有人阐明并希望指导我正确...这是代码
-(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.
我希望我包含了足够的详细信息和我的代码的 sn-p,因此希望有人会帮助我和其他人也来。先感谢您。
【问题讨论】:
-
你在哪一行得到错误?
标签: ios objective-c sprite-kit skphysicsbody skphysicsworld