为什么我的SpriteKit场景中的循环图像之间存在间隙?

基准点13

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

//地面节点的声明。

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
    }

在循环播放时,两个图像之间还存在细微的间隙。随着我增加使用游戏速度变量循环播放它们的速度,此差距会增大。

有人可以向我解释我做错了什么吗?

我已经检查过图像本身没有引起问题。

谢谢,

史蒂文

冷钢

差距可能是因为更新方法每秒调用约60次(如果我没记错的话,默认值为60 fps),则应该使用它SKAction来简单地翻转图像,这样会更加高效。这是您的起点:

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

为什么文本行之间存在间隙?

为什么函数堆栈框架中的参数,变量和框架指针之间存在间隙?

为什么水平滚动视图内容之间存在间隙?

为什么框形阴影和元素之间存在间隙?

为什么导航和标题div之间存在间隙/空间?

ListView - 为什么我的小部件之间有黄色间隙?

为什么我的div元素之前存在随机间隙?

为什么两个css表之间存在间隙?但是当我使用块代替时不是吗?

为什么我的徽标和导航栏之间存在巨大的可点击间隙,以及如何消除它?

CSS中图像之间的间隙

为什么我在堆栈中启动的变量之间存在“差距”?

为什么我的JavaScript代码中可能存在无限循环?

为什么在场景之间来回切换时SpriteKit会崩溃

为什么iOS 7.1和iOS 8之间的iOS SpriteKit场景/视图坐标不同?

为什么在js中运行两个单独的循环与单个for循环之间存在性能差异

为什么嵌套循环的顺序之间存在性能差异?

尽管将其padding设置为0,但为什么在LinearLayout中仍存在paddingLeft类型的间隙?

C中存在高迭代循环的程序没有给我输出..为什么呢?

为什么图像没有保存在我的 Django 应用程序的数据库中

为什么我的while循环中存在逻辑错误?

为什么我在图像网格之间出现随机空间?

为什么我的场景为空?

当我在react-native中设置borderLeftWidth = 1时,为什么会出现间隙?

SpriteKit中的场景

在 SpriteKit 中改变场景

如何在flex容器中获取图像之间的垂直间隙

HTML电子邮件-Outlook 2013中图像之间的间隙

我如何在 bs4 中的轮播中集中并缩小两个图像之间的间隙?

在精灵图像之间添加间隙