2016-07-17 6 views
-4
import Foundation 
import SpriteKit 

class MovingGround : SKSpriteNode { 

    let MovingGroundTexture = SKTexture(imageNamed: "MovingGround") 

    init(size: CGSize) { 
     super.init(texture: nil, color: nil, size:CGSizeMake(size.width, size.height)) 
     anchorPoint = CGPointMake(0, 0) 
     position = CGPointMake(0.0, 0.0) 
     zPosition = 1 
    } 

    required init?(coder aDecoder: NSCoder) { 
     fatalError("init(coder:) has not been implemented") 
    } 

} 

color: nil에서 오류가 계속 발생합니다. 어떻게 변경합니까?Nil이 예상되는 인수 유형 'UIColor'과 호환되지 않습니다.

+0

nil 대신 UIColor 인스턴스를 제공합니까? – Paulw11

+2

그건 그렇고, '크기'는 크기입니다. 그것의 너비와 높이를 떼어 내고 CGSizeMake를 통해 그것을 다시 모으는 것은 바보입니다. – matt

답변

3

오류 메시지에서 알 수 있듯이 nil은 색이 아닙니다. init(texture:color:size:)에 전화 할 경우 실제 색상을 제공해야합니다. 기본적으로 흰색을 제안합니다.

super.init(texture: nil, color: UIColor.whiteColor(), size:size) 
관련 문제