ios - SpriteKit : how to smoothly animate SKCameraNode while tracking node but only after node moves Y pixels?

标签 ios sprite-kit sknode skcameranode

This question和其他人讨论如何使用 SKCameraNode 跟踪 SpriteKit 中的节点。

但是,我们的需求各不相同。

其他解决方案,例如在SKScene的update(_ currentTime: CFTimeInterval)中更新相机位置,是行不通的,因为我们只想在节点移动了Y像素后调整相机位置在屏幕下方。

换句话说,如果节点向上移动 10 个像素,相机应该保持静止。如果节点向左或向右移动,相机应保持静止。

我们尝试随着时间而不是立即为相机的位置设置动画,但是在 update(_ currentTime: CFTimeInterval) 内针对相机运行 SKAction 无法执行任何操作。

最佳答案

我很快就做了这个。我相信这就是您要找的? (实际动画很流畅,只是我不得不压缩 GIF)

enter image description here

这是更新代码:

-(void)update:(CFTimeInterval)currentTime {
    /* Called before each frame is rendered */

    SKShapeNode *ball = (SKShapeNode*)[self childNodeWithName:@"ball"];
    if (ball.position.y>100) camera.position = ball.position;

    if (fabs(ball.position.x-newLoc.x)>10) {
        // move x
        ball.position = CGPointMake(ball.position.x+stepX, ball.position.y);
    }

    if (fabs(ball.position.y-newLoc.y)>10) {
        // move y
        ball.position = CGPointMake(ball.position.x, ball.position.y+stepY);
    }
}

关于ios - SpriteKit : how to smoothly animate SKCameraNode while tracking node but only after node moves Y pixels?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40969539/

相关文章:

ios - pod 更新后出现许多构建错误

swift - Sprite 出现在节点数中但不可见

ios - 获取 SKSpriteNode 的旋转角度

ios - SpriteKit : how to iterate through ancestors of a node?

swift - 移动时如何访问 SKSpriteNode 子类的对象(Swift)

ios - 在两点之间添加 block 。 SpriteKit

ios - sqlite for swift 不稳定

iphone - 如何在触摸时获得像素颜色?

ios - 在没有登录提示的情况下自动登录 Core Api 上的 Dropbox 帐户

xcode - 如何使用 Swift Spritekit 每 3 秒调用一个函数