0

Im a bit confused. I am trying to move one CCSprite onto the position of another CCSprite. I figured it would be simple, but the CCSprite isn't positioning correctly. I have 2 CCSprites:

//Get Position of EMPTY SPRITE
CCSprite *sprite = (CCSprite*)[self getChildByName:[NSString stringWithFormat:@"%d", kEMPTY] recursively:NO];

 //GET DRAGGED SQUARE
 CCSprite *spriteMove = (CCSprite*)[self getChildByName:[NSString stringWithFormat:@"%d", DragStartSquare] recursively:NO];

I am then trying to get the position of the EMPTY SPRITE (Its not actually empty) by doing

CGPoint worldCoord = [sprite convertToWorldSpace: sprite.position];

I am then animating it with:

id action1 = [CCActionMoveTo actionWithDuration:duration position:worldCoord];

This sends the sprite off the screen. What am I doing wrong?

Allreadyhome
  • 1,252
  • 2
  • 25
  • 46

1 Answers1

0

You need to convert back into the target sprite's node space:

CGPoint targetNodeCoord = [spriteMove convertToNodeSpace: [sprite convertToWorldSpace: sprite.position]];
CCAction *action1 = [CCActionMoveTo actionWithDuration:duration position:targetNodeCoord];
godel9
  • 7,340
  • 1
  • 33
  • 53
  • Thanks. Its closer but still positions it wrong. It goes above. – Allreadyhome Sep 01 '14 at 16:35
  • Are the two sprites the same size? Do they have the same anchor point? Also, just noticed the sprites are both children of the same parent node, so I think you can skip all the coordinate transformations entirely. – godel9 Sep 01 '14 at 16:50