CGPointMake in Swift

假装没事ソ 提交于 2019-12-06 16:36:44

问题


How to use CGPointMake in Swift? Is there an equivalent for it? I am getting an error:

Use of unresolved identifier 'CGPointMake'

Basically, I am trying to assign a position to a Sprite Kit node and cannot figure out how to do it in Swift.

class PlayerSpaceship: Spaceship {

    func launchMissile() {

        var missile = Missile.playerMissile()

        // This line gives above mentioned error.    
        missile.position = CGPointMake(0.0, 0.0) 
    }
}

回答1:


Use CGPoint(x: Float, y: Float)




回答2:


You call it a little differently, without the make.

CGPoint(x: 10, y: 20)



回答3:


Xcode 6.3.1 shows 4 different Swift initializers for CGPoint. They are:

CGPoint()
CGPoint(x: CGFloat, y: CGFloat)
CGPoint(x: Double, y: Double)
CGPoint(x: Int, y: Int)



回答4:


In the code it should looks like this (Xcode 6.1):

let point: CGPoint = CGPoint(x:10,y:10)



回答5:


Or also, you can use CGFloat type for CGPoint

 CGPoint(x: CGFloat, y: CGFloat)


来源:https://stackoverflow.com/questions/24070408/cgpointmake-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!