当屏幕被触摸时,如何让“便便”出现在某个地方?

时间:2014-03-07 20:59:13

标签: ios sprite-kit

我正在用精灵套装制作游戏,对于iphone而言我是一个菜鸟哈哈。无论如何,这是我到目前为止的代码,但不是在我触摸的地方出现的便便,我希望它出现在我选择的地方。

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
 /* Called when a touch begins */

for (UITouch *touch in touches) {
    CGPoint location = [touch locationInNode:self];

    SKSpriteNode *poo = [SKSpriteNode spriteNodeWithImageNamed:@"poo"];

    poo.position = location;

    poo.zPosition = 5;

    [poo setScale:0.2f];


    //next line adds gravity to the poo.
    poo.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:poo.size.width/2];

    [self addChild:poo];
}

}

1 个答案:

答案 0 :(得分:1)

只需创建一个包含所需位置的CGPoint并将其设置为一个位置:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{
    CGPoint yourLocationOfChoice = CGPointMake(200.0f, 200.0f);

    SKSpriteNode *poo = [SKSpriteNode spriteNodeWithImageNamed:@"poo"];

    poo.position = yourLocationOfChoice;

    ...
}