在spritekit中将项目堆叠在一起

时间:2014-04-26 04:18:06

标签: sprite-kit

大家好我正在建造一个墙砖建造者游戏,砖块变老并打破,但这个玩家需要移动到破碎砖的位置并修复它,到目前为止这里是我的代码,但我卡住了关于如何自动将我的玩家移动到墙壁的位置,以便玩家只需要弄乱工具来修复墙壁。因此,玩家的动作应该基于破碎的砖块自动进行。

这里是我放置砖块的代码,但它们并没有像图片中那样堆叠在一起:

-(void) addBricks:(CGSize) size {
for (int i = 0; i < 10; i++) {
    SKSpriteNode *brick = [SKSpriteNode spriteNodeWithImageNamed:@"Wallbrick"];

    // add a static physics body
    brick.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:brick.frame.size];
    brick.physicsBody.dynamic =  NO;
    brick.physicsBody.categoryBitMask = brickCategory;
    brick.physicsBody.affectedByGravity = YES;
    // brick.position = CGPointMake(self.size.width*0.75, self.size.height);

    int xPos = size.width*0.75;  // here is where I am stock to generate automatic bricks and stack them on top of each other vertically.
    int yPos = size.height/20 * (i+0.5);
    brick.position = CGPointMake(xPos, yPos);

    [self addChild:brick];

}
}

- (void) movePlayer {
    SKSpriteNode *player = [SKSpriteNode spriteNodeWithImageNamed:@"player"];
    player.position = CGPointMake(CGFloat x, <#CGFloat y#>); // here is where I am stock
    [self addBricks:player];
}

enter image description here

0 个答案:

没有答案