this is my background http://s13.postimg.org/6zejiqc87/1429994667798.png
in current code user can move sprite to any location, but I want the user to only move sprite to specific location. I have one Sprite (s1) I want to move it to specific position as you can see my background have line and dots and these dots are the position I want the user to be able to move the sprite from 1 to 2 and then from 2 to 3 but they can't skip one position for example they can't move sprite from 1 to 3 or from 2 to 4
I don't know how to get the x,y location of the dots in the background
- (id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
// 1) Loading the background
_background = [SKSpriteNode spriteNodeWithImageNamed:@"mybackground"];
[_background setName:@"background"];
[_background setAnchorPoint:CGPointZero];
[self addChild:_background];
// 2) Loading the images
// NSArray *imageNames = @[@"s1", @"s2"];
NSArray *imageNames = @[@"s1"];
for(int i = 0; i < [imageNames count]; ++i) {
NSString *imageName = [imageNames objectAtIndex:i];
SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithImageNamed:imageName];
[sprite setName:kAnimalNodeName];
float offsetFraction = ((float)(i + 1)) / ([imageNames count] + 1);
[sprite setPosition:CGPointMake(size.width * offsetFraction, size.height / 2)];
[_background addChild:sprite];
}
}
return self;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint positionInScene = [touch locationInNode:self];
[self selectNodeForTouch:positionInScene];
}