Ios 精灵-如何只触摸屏幕的某些部分?

Ios 精灵-如何只触摸屏幕的某些部分?,ios,touch,sprite-kit,sprite,area,Ios,Touch,Sprite Kit,Sprite,Area,我正在做一个游戏,我只想让用户触摸屏幕的边缘?我有什么办法可以做到这一点吗 下面的代码允许用户触摸屏幕上的任何地方,但我希望他们只触摸屏幕的某些部分 谢谢你的时间和回答 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { for (UITouch *touch in touches) { CGPoint location = [touch locationInNode:self];

我正在做一个游戏,我只想让用户触摸屏幕的边缘?我有什么办法可以做到这一点吗

下面的代码允许用户触摸屏幕上的任何地方,但我希望他们只触摸屏幕的某些部分

谢谢你的时间和回答

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

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

        SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithImageNamed:@"wall"];

        sprite.position = location;
        sprite.scale = 0.5;
        sprite.name = @"wall"; // Needed For Release Thing
        sprite.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:sprite.frame.size];
        sprite.physicsBody.dynamic = NO;
        sprite.physicsBody.categoryBitMask = wallCategory;


        SKAction *wait = [SKAction waitForDuration:0.4];
        SKAction *delete = [SKAction removeFromParent];


        SKAction *sequence = [SKAction sequence:@[wait, delete, ]];
        [sprite runAction: sequence];

        [self addChild:sprite];

    }
}

我没有测试这个,所以我不确定它是否有效

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

    if (((location.x < leftTouchArea) || (location.x > rightTouchArea)) && ((location.y < upperTouchArea) || (location.y > lowerTouchArea))) 
    {

        SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithImageNamed:@"wall"];

        sprite.position = location;
        sprite.scale = 0.5;
        sprite.name = @"wall"; // Needed For Release Thing
        sprite.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:sprite.frame.size];
        sprite.physicsBody.dynamic = NO;
        sprite.physicsBody.categoryBitMask = wallCategory;


       SKAction *wait = [SKAction waitForDuration:0.4];
       SKAction *delete = [SKAction removeFromParent];


       SKAction *sequence = [SKAction sequence:@[wait, delete, ]];
       [sprite runAction: sequence];

       [self addChild:sprite];
    }

}
用于(UITouch*触摸屏){
CGPoint位置=[触摸位置Innode:self];
if(((location.xrightouchArea))&&((location.ylowerTouchArea)))
{
SKSpriteNode*sprite=[SKSpriteNode SPRITENODEWITHIMAGENAME:@“墙”];
sprite.position=位置;
sprite.scale=0.5;
sprite.name=@“墙”;//需要发布东西
sprite.physicsBody=[skphysicsbodyWithRectangleOfSize:sprite.frame.size];
sprite.physicsBody.dynamic=否;
sprite.physicsBody.categoryBitMask=墙类别;
SKAction*wait=[SKAction waitForDuration:0.4];
SKAction*delete=[SKAction removeFromParent];
SKAction*序列=[SKAction序列:@[wait,delete,]];
[精灵运行操作:序列];
[self addChild:sprite];
}
}

即使它不起作用,您解决此问题的方法也是完全正确的。