繁体   English   中英

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

[英]How can i make the 'poo' appear in a certain place when the screen is touched?

我正在用精灵套装制作游戏,对于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;

    ...
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM