Note that there are some explanatory texts on larger screens.

plurals
  1. POrestricting touchesMoved to certain objects
    primarykey
    data
    text
    <p>I have 8 tiles laid out in a 3x3 grid with one blank spot. However, the only tiles that can move are the ones that are next to the blank spot.</p> <p>I have a centerCoordinate method that grabs the center coordinates of whatever tile you touch:</p> <pre><code>- (CGPoint) centerCoordinate: (NSSet*)touches withEvent:(UIEvent*) event { UITouch* touch = [touches anyObject]; location = [touch locationInView:self]; centerCoord = [touch locationInView:self.superview]; centerCoord.x += self.frame.size.width/2-location.x; centerCoord.y += self.frame.size.height/2-location.y; self.center = centerCoord; return centerCoord; } </code></pre> <p>In my touchesMoved method, I thought that adding a simple if check would work to make sure any tiles along a certain x-axis could move:</p> <pre><code>- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event { if ([self centerCoordinate:touches withEvent:event].x == 374) { NSLog(@"got here"); UITouch* touch = [touches anyObject]; CGPoint tileLocation = [touch locationInView:self.superview]; tileLocation.x += self.frame.size.width/2-location.x; tileLocation.y += self.frame.size.height/2-location.y; self.center = tileLocation; NSLog(@"got here2"); } } </code></pre> <p>When I attempt move tiles, the "got here" and "got here2" both print out but the tiles do not move. If I remove the if statement the tiles can move freely.</p> <p>Edit: When I changed touches moved to this, I can move the tiles that are not in x = 374. If I move at tile to x = 374, it locks into place after I let go of it.</p> <pre><code>- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event { NSLog(@"---1---"); UITouch* touch = [touches anyObject]; CGPoint tileLocation = [touch locationInView:self.superview]; if ([self centerCoordinate:touches withEvent:event].x == 374) { NSLog(@"---2---"); tileLocation.x += self.frame.size.width/2-location.x; tileLocation.y += self.frame.size.height/2-location.y; NSLog(@"---3---"); } self.center = tileLocation; NSLog(@"---4---"); } </code></pre> <p>Any ideas of what would be causing this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload