31

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) 
    }
}
TheNeil
  • 3,321
  • 2
  • 27
  • 52
Rafał Sroka
  • 39,540
  • 23
  • 113
  • 143

5 Answers5

73

Use CGPoint(x: Float, y: Float)

Joseph Mark
  • 9,298
  • 4
  • 29
  • 31
11

You call it a little differently, without the make.

CGPoint(x: 10, y: 20)
Connor Pearson
  • 63,902
  • 28
  • 145
  • 142
6

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)
mike663
  • 623
  • 5
  • 12
4

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

let point: CGPoint = CGPoint(x:10,y:10)
Cœur
  • 37,241
  • 25
  • 195
  • 267
Frank Schaefer
  • 119
  • 1
  • 4
0

Or also, you can use CGFloat type for CGPoint

 CGPoint(x: CGFloat, y: CGFloat)