CGPointMake in Swift

2020-08-09 05:07发布

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) 
    }
}

5条回答
Summer. ? 凉城
2楼-- · 2020-08-09 05:41

Use CGPoint(x: Float, y: Float)

查看更多
做自己的国王
3楼-- · 2020-08-09 05:41

Or also, you can use CGFloat type for CGPoint

 CGPoint(x: CGFloat, y: CGFloat)
查看更多
趁早两清
4楼-- · 2020-08-09 05:43

You call it a little differently, without the make.

CGPoint(x: 10, y: 20)
查看更多
不美不萌又怎样
5楼-- · 2020-08-09 05:48

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)
查看更多
家丑人穷心不美
6楼-- · 2020-08-09 05:59

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

let point: CGPoint = CGPoint(x:10,y:10)
查看更多
登录 后发表回答