1

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' が原因でアプリを終了します。 (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. 

十分な詳細とコードのスニペットが含まれていることを願っているので、誰かが私や他の人も同様に来るのを助けてくれることを願っています. 前もって感謝します。

4

1 に答える 1

1

する必要があります

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

それ以外の

NSArray *arrays = [self platformBars];

[self platformBars]は可変配列であり、arrays不変であるためです。
編集
そして、ところで、配列はSKSpriteNodes であり、物理体ではありません。そう

node.physicsBody = [SKPhysicsBody bodyWithBodies:arrays];

する必要があります

NSMutableArray *mArray=[NSMutableArray new];
for (SKSpriteNode *anySpriteNode in arrays){
[mArray addObject:anySpriteNode.physicsBody];
}
node.physicsBody = [SKPhysicsBody bodyWithBodies:mArray.copy];
于 2014-04-24T09:09:16.420 に答える