6월, 2015의 게시물 표시

[swift] SkSpriteKit 을 이용한 ProgressBar 만들기

일단 프로그레스 바를 생성한다. 배경을 사용한 부분과 바를 사용할 부분으로 나누어 생성한다. 바 부분이 앞으로 나오면 된다. 여기서 중요한 것은 각 노드의 이름이다. 노드의 이름으로 상태를 표시하기 때문이다. func create_ProgressTimer() {         let progress = SKSpriteNode (color: SKColor . darkGrayColor (), size: CGSizeMake ( 100 , 25 ))         progress. anchorPoint = CGPointMake ( 0 , 0.5 )         progress. position = CGPointMake ( 10 , CGRectGetHeight ( self . frame )- 20 )         progress. name = "progress"         self . addChild (progress)         let bar = SKSpriteNode (color: UIColor.RedColor() , size: progress. size )         bar. position = CGPointMake ( 0 , 0 )         bar. anchorPoint = CGPointMake ( 0 , 0.5 )         bar. xScale = 1.0 ;         bar. zPosition = progress. zPosition + 0.1         bar. name = "bar"         progress. addChild (bar)     } 화면이 업데이트 할 때 바의 크기를 조정하면 된다. override func update(currentTime: CFTimeInterval ) {     enumerateChildNodesWithName ( "/progress/bar&qu

[swift] 시간을 이용한 랜덤함수

시간을 이용한 랜덤함수 보통 랜덤함수를 사용하면 같은 경우가 나타난다. 그래서 시간을 이용한 랜덤함수를 만들면 게임등에 사용할 수 있다. 터치한 시간이 매번 달라지니까... func RandomValue(count: Int ) -> Int {         // 수시로 변하는 수 얻기         let date = NSDate ()         let calendar = NSCalendar . currentCalendar ()         let calUnit: NSCalendarUnit = .CalendarUnitHour | .CalendarUnitMinute | .CalendarUnitSecond         let dateComp = calendar. components (calUnit, fromDate: date)         let timeValue = dateComp. hour + dateComp. minute + dateComp. second                  return timeValue % count     }