如何使视图/相机遵循Uiimageview



我正在为我的游戏制作一个场景。现在我正在为iPhone 5-5s-5c屏幕工作。场景比普通 iPhone 5-5s-5c 的屏幕宽度大,因此模拟尺寸是自由形状的。

现在,你应该在障碍物之间移动这个图像。 视图/相机应该遵循uiimageView。

这是我如何移动图像的一些代码

    -(IBAction)left { goLeft = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(goLeft) userInfo:nil repeats:YES]; if (goLeft == nil) { goLeft = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(goLeft) userInfo:nil repeats:YES]; }
}
-(IBAction)stopLeft { [goLeft invalidate]; goLeft = nil;
}

-(void)goLeft { ball2.center = CGPointMake(ball2.center.x -3.5, ball2.center.y);{
 // left is connected to touch down 
// stopLeft is connected to Touch up inside
// Thanks for any help :)

@cilus-stian 你的问题的先前版本被标记为SpriteKit,所以我假设你使用SpriteKit。如果您不使用它,请告诉我,我将删除无关紧要的答案。

所以你想要的是你的相机跟随你的图像(ball2)。

您可以简单地创建一个SKCameraNode,它完全可以执行您想要的操作(对不起,我不知道Objc语法):

// Declare your camera
var camera: SKCameraNode = SKCameraNode()
// Add it to your scene (didMoveToView or init)
self.camera = camera
// In the update() function
self.camera.position = ball2.position

有关SKCameraNode的更多详细信息

另外,不确定你如何/为什么使用UIImageView,但也许你应该考虑使用SKSpriteNode来显示你的球。

最新更新