【问题标题】:The Child SKSpriteKITnodes in the coordinate system doesn't work坐标系中的 Child SKSpriteKITnodes 不起作用
【发布时间】:2015-06-07 21:59:56
【问题描述】:

坐标系中的子 SKSpriteKITnodes 无法正常工作我正在尝试将 SKSprite 节点从上到下移动但它们在中间停止?

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];

【问题讨论】:

    标签: ios objective-c sprite-kit skspritenode coordinate-systems


    【解决方案1】:

    SKSpriteNodeanchorPoint 默认为(0.5, 0.5)。因此,当[self dropNode].position.y == 0 正确时,子节点将位于其父节点SKSpriteNode 的中间。

    如果您希望硬币移动到dropNode 的底部,您可以将dropNodeanchorPoint 设置为(x, 0)(其中x 是0-1 范围内的任何值)。或者您可以将move 更改为:

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

    【讨论】:

    • 谢谢这个帮助
    • @Aditya Kasturi,没关系,很高兴我能帮上忙 :) 如果它解决了您的问题,您会考虑将其标记为正确吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多