斯威夫特编译器错误:'双'是无法转换为CGFloat的 [英] Swift Compiler error: 'Double' is not convertible to CGFloat

查看:124
本文介绍了斯威夫特编译器错误:'双'是无法转换为CGFloat的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始学习斯威夫特。我创建了一个游戏项目和模板走了过来。我没有做任何事情到code任何责任。我试图运行该项目,但一个编译器错误弹出。

I just began learning Swift. I created a game project and a template came up. I have not done anything to the code whatsoever. I tried to run the project but a compiler error popped up.

我要了一个教程,因此它可能是坏了我的环境或书是已经过时了。

I'm going off a tutorial so it could be something wrong with my environment or the book is already outdated.

斯威夫特编译器错误:'双'是无法转换为CGFloat的

Swift Compiler error: 'Double' is not convertible to CGFloat

import SpriteKit

class GameScene: SKScene {
    override func didMoveToView(view: SKView) {
        /* Setup your scene here */
        let myLabel = SKLabelNode(fontNamed:"Chalkduster")
        myLabel.text = "Hello, World!";
        myLabel.fontSize = 65;
        myLabel.position = CGPoint(x:CGRectGetMidX(self.frame), y:CGRectGetMidY(self.frame));

        self.addChild(myLabel)
    }

    override func mouseDown(theEvent: NSEvent) {
        /* Called when a mouse click occurs */

        let location = theEvent.locationInNode(self)

        let sprite = SKSpriteNode(imageNamed:"Spaceship")
        sprite.position = location;
        sprite.setScale(0.5)

        let action = SKAction.rotateByAngle(M_PI, duration:1)
        sprite.runAction(SKAction.repeatActionForever(action))

        self.addChild(sprite)
    }

    override func update(currentTime: CFTimeInterval) {
        /* Called before each frame is rendered */
    }
}

出现的错误动作,让= SKAction.rotateByAngle(M_PI,持续时间:1)

下面是该项目设置的屏幕截图

Here is a screenshot of the project settings

推荐答案

您可以将其与转换CGFloat的(M_PI)

例如下面的code应该在你的情况下工作(注意使用 CGFloat的

For example the following code should work in your case (note the use of CGFloat)

let action = SKAction.rotateByAngle(CGFloat(M_PI), duration:1)

这篇关于斯威夫特编译器错误:'双'是无法转换为CGFloat的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆