我的应用程序中存在更多问题。我的错误是正如标题所示:'CGFloat'不可转换为'浮动'等更多
- Swift编译器错误。
ERROR1: 'CGFloat的' 是无法转换为 '浮动'
代码为第1和第2个错误:
self.setPositionRelativeBot(pipeBot, x: xx, y: offset)
self.setPositionRelativeTop(pipeTop, x: xx, y: offset + space)
这里是整个FUNC:
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)
}
- Swift编译器错误。
ERROR1: '浮动' 不等同于 'UINT8'
代码为第1错误:
vel -= 85 - (self.view!.bounds.size.height - bird.position.y)
误差2: '?SKPhysicsBody' 不具有名为构件 '速度'
代码的第二错误:
bird.physicsBody.velocity = CGVectorMake(0, vel)
这里是整个FUNC:
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
}
}
- Swift编译器错误。
ERROR1: 'CGFloat的' 不等于 'UINT8'
代码的第一和第二误差(同样的错误都行):
ground1.position.x -= movingSpeed
ground2.position.x -= movingSpeed
误差2: 不能调用' - ='带有类型参数列表'(@lvalue CGFloat,$ T9)'
代码为第三和第四个错误(相同错误两行):
background1.position.x -= movingSpeed/3
background2.position.x -= movingSpeed/3
误差3: 'CGFloat的' 不等同于 'UINT8'
pipe.position.x -= movingSpeed
这里是整个FUNC:
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)"
}
}
}
我希望有你们的可以算因为我不能:)
您需要明确地进行大量转换,或者正确输入变量。例如'让抵消:CGFloat = ...'或'CGFloat(抵消)' – sapi 2014-09-29 07:47:06
@sapi我是一个需要简单解释的人,我不明白你的意思,你想让我做什么? :/ – StigPing 2014-09-29 07:55:43
而不是投票,人们应该解释为什么。 – StigPing 2014-09-29 08:55:56