7

アプリ内でさらに問題があります。私のエラーは、タイトルが示すとおりです。

  1. Swift コンパイラ エラー。

エラー 1: 'CGFloat' は 'Float' に変換できません

1 番目と 2 番目のエラーのコード:

self.setPositionRelativeBot(pipeBot, x: xx, y: offset)
self.setPositionRelativeTop(pipeTop, x: xx, y: offset + space)

ここに関数全体があります:

func spawnPipeRow(offs: Float)
    {
        let offset = offs - space / 2

        let pipeBot = mainPipe.copy() as Pipe
        let pipeTop = mainPipe.copy() as Pipe

        pipeBot.texture = SKTexture(imageNamed: "BotPipe")
        pipeTop.texture = SKTexture(imageNamed: "TopPipe")

        pipeBot.texture!.filteringMode = SKTextureFilteringMode.Nearest
        pipeTop.texture!.filteringMode = SKTextureFilteringMode.Nearest

        pipeBot.isBottom = true

        let xx = self.view!.bounds.size.width

        self.setPositionRelativeBot(pipeBot, x: xx, y: offset)
        self.setPositionRelativeTop(pipeTop, x: xx, y: offset + space)

        pipeBot.physicsBody = SKPhysicsBody(rectangleOfSize: pipeBot.size)
        pipeTop.physicsBody = SKPhysicsBody(rectangleOfSize: pipeTop.size)

        pipeBot.physicsBody!.dynamic = false
        pipeTop.physicsBody!.dynamic = false

        pipeBot.physicsBody!.contactTestBitMask = birdCategory
        pipeTop.physicsBody!.contactTestBitMask = birdCategory

        pipeBot.physicsBody!.collisionBitMask = birdCategory
        pipeTop.physicsBody!.collisionBitMask = birdCategory

        pipes.append(pipeBot)
        pipes.append(pipeTop)

        self.addChild(pipeBot)
        self.addChild(pipeTop)
    }

  1. Swift コンパイラ エラー。

エラー 1: 'Float' は 'UInt8' と同一ではありません

最初のエラーのコード:

vel -= 85 - (self.view!.bounds.size.height - bird.position.y)

エラー 2: 'SKPhysicsBody?' 'velocity' という名前のメンバーがありません

2 番目のエラーのコード:

bird.physicsBody.velocity = CGVectorMake(0, vel)

ここに関数全体があります:

override func touchesBegan(touches: NSSet, withEvent event: UIEvent)
    {
        if (!bird.physicsBody!.dynamic)
        {
            //First touch

            self.spawnPipeRow(0)

            bird.physicsBody!.dynamic = true

            bird.physicsBody!.velocity = CGVectorMake(0, 175)

            scoreLabel.hidden = false

            isMoving = true
        } else if (isMoving)
        {
            var vel: Float = 200

            if (self.view!.bounds.size.height - bird.position.y < 85)
            {
                vel -= 85 - (self.view!.bounds.size.height - bird.position.y)
            }

            bird.physicsBody.velocity = CGVectorMake(0, vel)
        } else
        {
            overlay.removeFromParent()

            for pi in pipes
            {
                pi.removeFromParent()
            }

            pipes.removeAll(keepCapacity: false)

            score = 0

            bird.physicsBody!.dynamic = false
            bird.position = CGPoint(x: 150, y: view!.bounds.size.height / 2 - 10)

            scoreLabel.hidden = true

            isGroundMoving = true
        }
    }

  1. Swift コンパイラ エラー。

エラー 1: 'CGFloat' は 'UInt8' と同一ではありません

1 番目と 2 番目のエラーのコード (両方の行で同じエラー):

ground1.position.x -= movingSpeed
ground2.position.x -= movingSpeed

エラー 2: タイプ '(@lvalue CGFloat, $T9)' の引数リストで '-=' を呼び出すことはできません

3 番目と 4 番目のエラーのコード (両方の行で同じエラー):

background1.position.x -= movingSpeed / 3
background2.position.x -= movingSpeed / 3

エラー 3: 'CGFloat' は 'UInt8' と同一ではありません

pipe.position.x -= movingSpeed

ここに関数全体があります:

override func update(currentTime: CFTimeInterval)
    {
        if (isGroundMoving)
        {
            ground1.position.x -= movingSpeed
            ground2.position.x -= movingSpeed

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

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

            background1.position.x -= movingSpeed / 3
            background2.position.x -= movingSpeed / 3

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

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

            if (isMoving)
            {
                for (var i = 0; i < pipes.count; i++)
                {
                    let pipe = pipes[i]

                    if (pipe.position.x + (pipe.size.width / 2) < 0)
                    {
                        pipe.removeFromParent()

                        continue
                    }

                    if (pipe.position.x + (pipe.size.width / 2) < self.view!.bounds.size.width / 2 && pipe.isBottom && !pipe.pointAdded)
                    {
                        score++

                        pipe.pointAdded = true
                    }

                    pipe.position.x -= movingSpeed

                    if (i == pipes.count - 1)
                    {
                        if (pipe.position.x < self.view!.bounds.width - pipe.size.width * 2.0)
                        {
                            self.spawnPipeRow(self.randomOffset())
                        }
                    }
                }

                scoreLabel.text = "Score: \(score)"
            }
        }
    }

私にはできないので、皆さんの何人かが私のためにこれを理解できることを願っています:)

4

1 に答える 1