我想在我的图像上添加一个椭圆,在两个节点联系的位置:
func didBegin(_ contact: SKPhysicsContact) {
hitEnvironment(at: contactPoint)
let explosion = SKEmitterNode(fileNamed: "Explosion")!
explosion.position = contactPoint
addChild(explosion)
bullet.removeFromParent()
}
func hitEnvironment(at point: CGPoint) {
let renderer = UIGraphicsImageRenderer(size: environment.size)
let img = renderer.image { ctx in
currentImage.draw(at: CGPoint(x: 0, y: 0))
ctx.cgContext.addEllipse(in: CGRect(x: point.x, y: point.y, width: 64, height: 64))
ctx.cgContext.setBlendMode(.clear)
ctx.cgContext.drawPath(using: .fill)
}
environment = SKSpriteNode(texture: SKTexture(image: img))
}
第一点:我想知道为什么在hitEnvironment函数的最后一行代表environment.texture = SKTexture(image: img)
而不是environment = SKSpriteNode(texture: SKTexture(image: img))
时,我会得到一张黑色图像。
第二点:当我尝试添加椭圆时,没有任何反应。我是否必须先转换头寸,我该怎么做?