Skip to content

Resolve "Making Obstacles as separate class to reuse"

Closes #19

  • restructure the GameViews directory
  • create "Obstacle.swift"
  • remove or add comments

Example of use in SKScene class:

// ObstacleCreator
private let obstacleCreator: ObstacleCreator = ObstacleCreator()

// RectangleObstacle 
let rectObstacle = obstacleCreator.createRectObstacle(rectSize: CGSize(width: widthValue, height: heightValue), type: .StartPoint)
obstacle.position = CGPoint(x: xValue, y: yValue)
addChild(obstacle)

// CircleObstacle
let circleObstacle = obstacleCreator.createCircleObstacle(radius: radiusValue, type: .Normal)
addChild(circleObstacle)

// PathObstacle(arc)
let arcRadius: CGFloat = 10.0
let arc = UIBezierPath(arcCenter: CGPoint(x: 0, y: 0), radius: arcRadius, startAngle: CGFloat(0.0), endAngle: CGFloat(Float.pi), clockwise: false)
let arcObstacle = obstacleCreator.createPathObstacle(path: arc.cgPath, type: .EndPoint)
arcObstacle.position = CGPoint(x: xValue, y: yValue)
addChild(arcObstacle)

Merge request reports

Loading