我正在用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];
}

}

最佳答案

只需创建一个具有所需位置的CGPoint并将其设置为位置即可:

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

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

    poo.position = yourLocationOfChoice;

    ...
}

关于ios - 触摸屏幕时,如何使“便便”出现在某个位置?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22260542/

10-11 12:09