Je fais un jeu d'oiseau flappy. J'ai l'impression d'avoir un problème quand mon oiseau passe chaque mur/recueille une pièce de monnaie. Il y a 2 problèmes. 1 le jeu est en retard d'une milliseconde après la collecte. 2 Mon oiseau semble avoir 2 ou même 3 collisions à chaque fois créant un score de 2 ou 3, je ne peux pas obtenir ma tête autour de cela! Mon oiseau est une animation de texture 5, avec un corps de physique qui entoure sa forme complexe avec la texture: bird.texture! type de code.Collision détectée plusieurs fois.
J'ai essayé de comprendre cela pendant 4 jours maintenant il a mis les pauses sur mon application grand moment! S'il vous plaît Helpp !!!
func createScene(){
let bird1 = SKTexture(imageNamed: "1")
let bird2 = SKTexture(imageNamed: "2")
let bird3 = SKTexture(imageNamed: "3")
let bird4 = SKTexture(imageNamed: "4")
let bird5 = SKTexture(imageNamed: "5")
let birdAnimation = SKAction.repeatForever(SKAction.animate(with: [bird1, bird2, bird3, bird4, bird5], timePerFrame: 0.1))
let flyForever = SKAction.repeatForever(birdAnimation)
bird = SKSpriteNode(texture: bird1)
bird = CGSize(width: 65, height: 65)
bird = CGPoint(x: self.frame.width/1.5 - bird, y: self.frame.height/2)
bird(flyForever, withKey: "birdFly")
bird = SKPhysicsBody(texture: bird.texture!, size: CGSize(width: bird.size.width, height: bird.size.height))
bird.physicsBody?.categoryBitMask = physicsCategory.bird
bird.physicsBody?.collisionBitMask = physicsCategory.ground | physicsCategory.wall
bird.physicsBody?.contactTestBitMask = physicsCategory.ground | physicsCategory.wall | physicsCategory.score
bird?.affectedByGravity = false
bird.physicsBody?.isDynamic = true
self.addChild(bird)
func didBegin(_ contact: SKPhysicsContact) {
let firstBody = contact.bodyA
let secondBody = contact.bodyB
if firstBody.categoryBitMask == physicsCategory.score && secondBody.categoryBitMask == physicsCategory.bird{
score += 1
scoreLabel.text = "\(score)"
firstBody.node?.removeFromParent()
run(SKAction.playSoundFileNamed("tap.caf", waitForCompletion: false))
if score > UserDefaults().integer(forKey: "HIGHSCORE") {
saveHighScore()
}
}
else if firstBody.categoryBitMask == physicsCategory.bird && secondBody.categoryBitMask == physicsCategory.score{
score += 1
scoreLabel.text = "\(score)"
secondBody.node?.removeFromParent()
run(SKAction.playSoundFileNamed("tap.caf", waitForCompletion: false))
if score > UserDefaults().integer(forKey: "HIGHSCORE") {
saveHighScore()
}
}
func createWalls(){
let scoreNode = SKSpriteNode(imageNamed: "bird")
scoreNode.size = CGSize(width: 40, height: 40)
scoreNode.position = CGPoint(x: self.frame.width + 25, y: self.frame.height/2)
scoreNode.physicsBody = SKPhysicsBody(rectangleOf: scoreNode.size)
scoreNode.physicsBody?.affectedByGravity = false
scoreNode.physicsBody?.isDynamic = false
scoreNode.physicsBody?.categoryBitMask = physicsCategory.score
scoreNode.physicsBody?.collisionBitMask = 0
scoreNode.physicsBody?.contactTestBitMask = physicsCategory.bird