Reputation: 103
I am making a game and I only want the user to touch the edges of the screen? Is there any way I can do this?
The following code lets the user touch anywhere on the screen but I would like them to only touch certain parts of the screen.
Thank You For Time And Answers
-(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];
}
}
Upvotes: 0
Views: 54
Reputation: 1082
I didnt test this so I'm not sure if it will work
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];
}
}
Upvotes: 1