【问题标题】:Why is there is a gap between my looping images in my SpriteKit scene?为什么我的 SpriteKit 场景中的循环图像之间存在间隙?
【发布时间】:2015-10-18 14:56:32
【问题描述】:

一开始我已经声明了节点。

//地面节点的声明。

var groundImage: SKSpriteNode = SKSpriteNode()
var groundImage2: SKSpriteNode = SKSpriteNode()

在 viewDidLoad 我有:

    //Creates an instance of both sprites that are of the same image that are to be lined up against each other in the x axis creating the illution of continuity.

    groundImage = SKSpriteNode(imageNamed: "Ground.png")
    groundImage2 = SKSpriteNode(imageNamed: "Ground.png")

    //Specifies the Z position of the images.

    groundImage.zPosition = 3
    groundImage2.zPosition = 3

    //Scales the images to the correct size of the screen.

    groundImage.size.width = self.frame.width
    groundImage.size.height = self.groundImage.size.height / 2

    groundImage2.size.width = self.frame.width
    groundImage2.size.height = self.groundImage2.size.height / 2

    //Specicies the x position of the images.  By offsetting the second you create the illution of a long, continuous image.

    groundImage.position.x = view.bounds.size.width * 0.5
    groundImage2.position.x = view.bounds.size.width * 1.5

    //Specifies the y postion of the images, obviously these are the same as they are not to be offset at any time.

    groundImage.position.y = (view.bounds.size.height - view.bounds.size.height) + self.groundImage.size.height / 2
    groundImage2.position.y = (view.bounds.size.height - view.bounds.size.height) + self.groundImage2.size.height / 2

    //Not sure what this does yet.

    groundImage.texture?.filteringMode = SKTextureFilteringMode.Nearest
    groundImage2.texture?.filteringMode = SKTextureFilteringMode.Nearest

    //Adds instances of the sprites to the scene.

    self.addChild(groundImage)
    self.addChild(groundImage2)

在我的更新方法中:

    //This is how the image is moved relative the number specified.  The number in the variable is how many pixels the frame is being moved each frame refresh.

    groundImage.position.x -= gameSpeed
    groundImage2.position.x -= gameSpeed

    if (groundImage.position.x <= -self.view!.bounds.size.width / 2)
    {
        groundImage.position.x = self.view!.bounds.size.width * 1.5 // - 2
    }


    if (groundImage2.position.x <= -self.view!.bounds.size.width / 2)
    {
        groundImage2.position.x = self.view!.bounds.size.width * 1.5 // - 2
    }

当两个图像循环播放时,它们之间仍然存在细微的差距。当我使用游戏速度变量提高它们的循环速度时,这种差距会增加。

谁能解释一下我做错了什么?

我已检查图像本身并没有导致问题。

谢谢,

史蒂文

【问题讨论】:

  • 你为什么不用SKAction呢?
  • 这个差距可能是因为更新方法在一秒钟内调用了大约 60 次(如果我没记错的话默认是 60 fps),你应该使用SKAction 来简单地翻转你的图像,它会是效率更高。这是您的起点developer.apple.com/library/ios/documentation/GraphicsAnimation/…
  • 谢谢,这有帮助。
  • 没问题!再来一次;)

标签: ios sprite-kit ios9


【解决方案1】:

差距可能是因为更新方法在一秒钟内调用了大约 60 次(如果我没记错的话,默认是 60 fps), 你应该使用SKAction 来简单地翻转你的图像, 它会更有效率。这是您的出发点:

https://developer.apple.com/library/ios/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/AddingActionstoSprites/AddingActionstoSprites.html

【讨论】:

  • 这有帮助,但我仍然在图像之间看到一条细线,比以前小得多,但仍然很明显。有什么想法吗?
  • 哦...将图像放大 1 个像素。
  • 为了掩盖这条线 - 我有这样的东西......我想我用了 3 张图片 - 我不记得了 - 你可以试着把这里的像素放大一点。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-29
  • 1970-01-01
相关资源
最近更新 更多