The Child SKSpriteKITnodes in the coordinate system doesn't work

62 views Asked by At

The Child SKSpriteKITnodes in the coordinate system doesn't work well I am trying to move the SKSprite nodes from Top To Bottom But they Get stop in the middle ?

ColorCoin *coin = [[ColorCoin alloc] initWithImageNamed: coinName] ;

SKAction *move = [SKAction moveToY:0 duration: 10];

CGFloat screenWidth = [self dropNode].size.width;


int x = arc4random() % (int) _dropNode.calculateAccumulatedFrame.size.width;

coin.zPosition =0.0;

coin.position = CGPointMake( x, _dropNode.calculateAccumulatedFrame.size.height-30);
coin.name = coinName;

[coin runAction: move];

[[self dropNode] addChild:coin];
1

There are 1 answers

1
ABakerSmith On

The anchorPoint of an SKSpriteNode is (0.5, 0.5) by default. Therefore, when [self dropNode].position.y == 0 it's correct the the child node will be in the middle of its parent SKSpriteNode.

If you want the coin to move to the bottom of dropNode you can either set the anchorPoint of dropNode to (x, 0) (where x is any value in the range 0-1). Or you can change move to:

SKAction *move = [SKAction moveToY:-screenWidth / 2 duration: 10];