Rafał Sroka
Rafał Sroka

Reputation: 40030

CGPointMake in Swift

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

Upvotes: 31

Views: 36307

Answers (5)

Frank Schaefer
Frank Schaefer

Reputation: 119

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

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

Upvotes: 4

mike663
mike663

Reputation: 623

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)

Upvotes: 6

user3837351
user3837351

Reputation:

Or also, you can use CGFloat type for CGPoint

 CGPoint(x: CGFloat, y: CGFloat)

Upvotes: 0

Connor
Connor

Reputation: 64644

You call it a little differently, without the make.

CGPoint(x: 10, y: 20)

Upvotes: 11

Joseph Mark
Joseph Mark

Reputation: 9418

Use CGPoint(x: Float, y: Float)

Upvotes: 72

Related Questions