Ich bin ein Spiel erstellen und ich habe Probleme, meine Kugeln in Richtung meines Joysticks spawnen. hier ist die Methode für meine Kugelnwie man ein SKAction in Richtung eines Joysticks Grad
func spawnBullets(){
let bullet = SKSpriteNode(imageNamed: "bullet.png")
bullet.zPosition = -5
bullet.position = CGPointMake(hero.position.x, hero.position.y)
bullet.xScale = 0.25
bullet.yScale = 0.25
bullet.physicsBody = SKPhysicsBody(rectangleOfSize: bullet.size)
bullet.physicsBody?.categoryBitMask = PhysicsCategory.bullet
bullet.physicsBody?.contactTestBitMask = PhysicsCategory.enemy
bullet.physicsBody?.affectedByGravity = false
bullet.physicsBody?.dynamic = false
let action = SKAction.moveToY(self.size.height + 30, duration: 1.0)
let actionDone = SKAction.removeFromParent()
bullet.runAction(SKAction.sequence([action, actionDone]))
self.addChild(bullet)
}
hier ist, wie ich in meinem
override func didMoveToView(view: SKView) {
_ = NSTimer.scheduledTimerWithTimeInterval(0.25, target: self,
selector: Selector ("spawnBullets"), userInfo: nil, repeats: true)
}
die Methode nenne und hier ist, wie ich codiert Berührungen Funktion bewegt (ich glaube, dass das Verfahren ist, dass ich bearbeiten müssen)
override func touchesMoved(touches: Set<UITouch>, withEvent event:
UIEvent?) {
for touch in touches {
let location = touch.locationInNode(self)
let v = CGVector(dx: location.x - joystickBase.position.x, dy:
location.y - joystickBase.position.y)
let angle = atan2(v.dy, v.dx)
let deg = angle * CGFloat(180/M_PI)
let length: CGFloat = joystickBase.frame.size.height/2
let xDist:CGFloat = sin(angle - 1.5709633) * length
let yDist:CGFloat = cos(angle - 1.5709633) * length
print(deg + 180)
if (stickActive == true) {
if (CGRectContainsPoint(joystickBase.frame, location)) {
joystick.position = location
}else{
joystick.position = CGPointMake(joystickBase.position.x -
xDist, joystickBase.position.y + yDist)
}
}
}
}
@ crashoveride777 –