functionality for rendering building impact
This commit is contained in:
parent
36ba0ba182
commit
ef24389b6b
|
@ -223,7 +223,11 @@ class GameScene: SKScene {
|
|||
// won't be detected in `didBegin`
|
||||
banana.name = ""
|
||||
|
||||
buildingNode.hitAt(point: buildingLocation)
|
||||
launchCompleted()
|
||||
buildingNode.hit(
|
||||
atPoint: buildingLocation,
|
||||
withImpactSize: CGSize(width: banana.size.width * 3.0, height: banana.size.width * 3.0)
|
||||
)
|
||||
}
|
||||
|
||||
func launchCompleted() {
|
||||
|
@ -237,9 +241,11 @@ class GameScene: SKScene {
|
|||
let newScene = GameScene(size: self.size)
|
||||
|
||||
newScene.gameViewController = self.gameViewController
|
||||
self.gameViewController.gameScene = newScene // 😐 not sure that tight coupling like this is the best
|
||||
|
||||
self.view?.presentScene(newScene, transition: self.sceneTransition)
|
||||
|
||||
self.gameViewController.changeCurrentPlayer()
|
||||
self.gameViewController.launchCompleted()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,16 +26,17 @@ class BuildingNode: SKSpriteNode {
|
|||
var currentImage: UIImage! {
|
||||
didSet {
|
||||
texture = SKTexture(image: currentImage)
|
||||
configurePhysics()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func setup() {
|
||||
name = NodeNames.building.rawValue
|
||||
currentImage = draw(size: size)
|
||||
|
||||
configurePhysics()
|
||||
}
|
||||
|
||||
|
||||
func draw(size: CGSize) -> UIImage {
|
||||
return renderer.image(actions: { (context: UIGraphicsImageRendererContext) in
|
||||
let cgContext = context.cgContext
|
||||
|
@ -66,7 +67,23 @@ class BuildingNode: SKSpriteNode {
|
|||
}
|
||||
|
||||
|
||||
func hitAt(point: CGPoint) {
|
||||
func hit(atPoint point: CGPoint, withImpactSize impactSize: CGSize) {
|
||||
let convertedPoint = CGPoint(x: point.x + (size.width / 2.0), y: abs(point.y - (size.height / 2.0)))
|
||||
|
||||
currentImage = renderer.image(actions: { (context: UIGraphicsImageRendererContext) in
|
||||
let cgContext = context.cgContext
|
||||
|
||||
currentImage.draw(at: CGPoint(x: 0, y: 0))
|
||||
|
||||
cgContext.addEllipse(in: CGRect(
|
||||
x: convertedPoint.x - (impactSize.width / 2.0),
|
||||
y: convertedPoint.y - (impactSize.height / 2.0),
|
||||
width: impactSize.width,
|
||||
height: impactSize.height
|
||||
))
|
||||
|
||||
cgContext.setBlendMode(.clear)
|
||||
cgContext.drawPath(using: .fill)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue