나는 SpriteKit 게임을 만들고있다. 나는 내가 만든 여섯 개의 대포를 가지고있다. 각 대포의 회전과 동기화되는 대포에서 대포를 쏘고 싶습니다. 각 캐논볼 사이에 1 초의 지속 시간이 필요합니다.회전 캐논에서 공을 쏘기
기본적으로 일정한 회전을하는 캐논은 회전과 같은 방향으로 포탄을 쏘고 있습니다.
extension CGFloat {
func degreesToRadians() -> CGFloat {
return self * CGFloat.pi/180
}
}
난에 가로 질러 운동 중 하나를 조정하는 방법을 알아낼 수 있어야하기 때문에 나는 거 한 대포의 코드를 넣어 해요 : 대포를 들어
은 내가 확장을 사용하고 있습니다 다른 사람. 여기에 하나입니다
func createBalls() {
let cannonBallLB = SKSpriteNode(imageNamed: "Ball")
cannonBallLB.name = "CannonBall"
cannonBallLB.position = CGPoint(x: -325, y: -420)
cannonBallLB.physicsBody = SKPhysicsBody(circleOfRadius:
cannonBallLB.size.height/2)
cannonBallLB.physicsBody?.affectedByGravity = false
cannonBallLB.zPosition = 3
cannonBallLB.setScale(0.1)
self.addChild(cannonBallLB)
}
THX :
func createCannons() {
let cannonLeftBottom = SKSpriteNode(imageNamed: "Cannon")
cannonLeftBottom.anchorPoint = CGPoint(x: 0.5, y: 0.5)
cannonLeftBottom.position = CGPoint(x: -325, y: -420)
cannonLeftBottom.zPosition = 4
cannonLeftBottom.setScale(0.4)
cannonLeftBottom.zRotation = CGFloat(65).degreesToRadians()
let rotateLB = SKAction.rotate(byAngle:
CGFloat(-65).degreesToRadians(), duration: 2)
let rotateBackLB = SKAction.rotate(byAngle:
CGFloat(65).degreesToRadians(), duration: 2)
let repeatRotationLB =
SKAction.repeatForever(SKAction.sequence([rotateLB,rotateBackLB]))
cannonLeftBottom.run(repeatRotationLB)
self.addChild(cannonLeftBottom)
}
것은 여기에 가로 질러 내 기능입니다!
그래서 코드가 올바르게 작동하지 않습니다. – ThrowingSpoon
ThrowingSpoon - 내가 분명하지 않은 경우 죄송합니다. 대포의 회전과 같은 방향으로 대포를 움직이는 코드를 작성하고 싶습니다. 대포의 회전이 잘 작동합니다. 그러나 그것은 내가 쓰고 싶은 대포의 움직임이다. – Flinigan