Tony_89
Tony_89

Reputation: 817

CCActionMoveTo sprite moving in wrong direction

Hi im currently working on a game where my player collects coins among other things. I have implemented collision detection for the coins and that is working, however when i collide with a coin i want to move the coin to the score label. The score label is located in the top right hand corner of my screen. The code i use for the collision can be seen bellow. The game is being developed using sprite builder which is why the collision may look different.

    -(bool)ccPhysicsCollisionBegin:(CCPhysicsCollisionPair *)pair player:(CCNode *)Player coin:(CCNode *)coin
    {
       coin.physicsBody.Sensor = YES;
       NSLog(@" scoreLabel x:%f y:%f", _scoreLabel.position.x,_scoreLabel.position.y);
       id move = [CCActionMoveTo actionWithDuration:1.0f position:ccp(_scoreLabel.position.x, _scoreLabel.position.y);
       NSLog(@"coin positon x:%f y:%f", coin.position.x, coin.position.y);

       [coin runAction:move];
       return YES;
    }

The _scoreLabels position is 177, 20 ive logged this to check its correct. The issue is when the coins moves it is moving to the left and and down, its not moving to the point specified. Thank you for any help and suggestions.

Upvotes: 0

Views: 105

Answers (2)

virgil debique
virgil debique

Reputation: 357

You say you know the label position as you output it, but what about the coin position, what does this return before and after the move?

If you go into SpriteBuilder and click on the physics node and ensure that it is at (0,0) in the properties panel (top, right window).

Upvotes: 0

bseh
bseh

Reputation: 467

Positions are related to their parents, so check if coin's parent and the score label's parent are the same. It might be the problem.

Upvotes: 0

Related Questions