Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. class GameScene: CCNode {
  2. // 物理ノード
  3. weak var _physicsNode:CCPhysicsNode!
  4.  
  5. // フレーム毎に呼び出されるメソッド
  6. override func update(delta: CCTime) {
  7. // ランダムに気球を生成します。
  8. if arc4random_uniform(100) == 0 {
  9. // バルーンを生成します。
  10. let balloonNode = CCBReader.load("Parts/BalloonNode")
  11. // 大きさをランダムにします。
  12. balloonNode.scale = Float(arc4random_uniform(25) + 25) * 0.01
  13.  
  14. // 現在の大きさを取得します。
  15. let width = balloonNode.children[0].contentSizeInPoints.width * CGFloat(balloonNode.scale)
  16. let height = balloonNode.children[0].contentSizeInPoints.height * CGFloat(balloonNode.scale)
  17.  
  18. // 上部へランダムに表示させます。
  19. balloonNode.position.x = CGFloat(arc4random_uniform(UInt32(self.contentSizeInPoints.width - width))) + width / 2
  20. balloonNode.position.y = self.contentSizeInPoints.height + height
  21.  
  22. // 物理ノードにバルーンを設置
  23. _physicsNode.addChild(balloonNode)
  24. }
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement