I am planning to place three cards on a view which I add to the background. However I wanted to combine two of the cards and replace the first card position with the new card position. Is there any way I can do this?

I am trying to read the selected node position by:

CGPoint position = CGPointMake([self nodeAtPoint:touchLocation].position.x, [self nodeAtPoint:touchLocation].position.y);

However what I read is (0,0).

What happened?


In your scene controller, you should do this inside -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event:

UITouch *touch = [touches anyObject];
CGPoint touchPos = [touch locationInNode:self];

touchPos will have the position inside your scene, and you can do:

if ([self.cardOne containsPoint:touchPos]){
    //Do something 
    CGPoint cardOnePosition = self.cardOne.frame.origin;

If you want to get what node are you touching in a better way, you can subclass SKSpriteNode (for your cards) and from there implement -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event, make sure inside init you make [self setUserInteractionEnabled:YES]. Then you could set up a delegate from this subclass that calls a method in your scene, and from your scene controll what to do better.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.