我为背景和另一个精灵节点设置了物理主体,但节点仍然可以离开边界。它不会从底部掉落,但它可以留在两侧。
SKSpriteNode *bg = [SKSpriteNode spriteNodeWithImageNamed:@"bg"];
bg.position = CGPointMake(self.scene.size.width/2, self.scene.size.height/2);
self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:self.frame];
self.physicsWorld.contactDelegate = self;
[self addChild:bg];
SKSpriteNode *player = [SKSpriteNode spriteNodeWithImageNamed:@"ball"];
player.position = CGPointMake(self.frame.size.width*.5, 200);
player.name = @"player";
player.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:30];
player.physicsBody.categoryBitMask = playerCategory;
player.physicsBody.contactTestBitMask = barCategory;
[self addChild:player];
我认为正在发生的是背景节点的主体比视图显示的更宽。我怎样才能使身体尺寸成为视野。
答案 0 :(得分:1)
将GameScene
中GameViewController
的初始化行更改为
GameScene *scene = [[GameScene alloc]
initWithSize:CGSizeMake(self.view.frame.size.width,
self.view.frame.size.height)];