I am trying to make simple game, but I have a problem. The node is too small. On iPhones with smaller screen size, the finger can't move it. On iPad and on simulator, however, the node can be moved due to larger sizes of the screens. Due to that, I know it's not the code that causes the issue.
Due to the fact that I am using this paddle image on many levels, I create it as separate file so I can implement it anywhere I want within the app.
Here is what I got:
PaddleNode.m
- (id)init
{
return [self initWithName:@"paddle"];
}
- (id)initWithName:(NSString *)name
{
self = [super init];
if (self) {
self = [PaddleNode spriteNodeWithImageNamed: @"board.png"];
self.userInteractionEnabled = YES;
self.name = name;
self.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:self.frame.size];
self.physicsBody.dynamic = NO;
self.physicsBody.usesPreciseCollisionDetection = YES;
self.physicsBody.categoryBitMask = paddleCategory;
self.physicsBody.collisionBitMask = emptyCategory;
self.currentTouchValue = nil;
}
return self;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
self.previousTouchesTimestamp = event.timestamp;
for (UITouch *touch in touches) {
self.currentTouchValue = [NSValue valueWithNonretainedObject:touch];
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
self.currentTouchValue = nil;
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UITouch *touch in touches) {
NSValue *key = [NSValue valueWithNonretainedObject:touch];
if ([key isEqualToValue:self.currentTouchValue]) {
CGPoint touchPoint = [touch locationInNode:self.scene];
CGPoint movePoint = CGPointMake(self.position.x, touchPoint.y);
if ([self withinParentFrame:movePoint])
self.position = movePoint;
}
}
}
- (BOOL)withinParentFrame:(CGPoint)point
{
CGFloat offset = self.size.height / 2;
if (point.y >= offset && point.y <= self.scene.frame.size.height - offset)
return YES;
else
return NO;
}
P.S. I am learning Objective-C by myself and English is not my first language. So, if it's OK, explain me like you would to little child.