samedi 25 juin 2016

Multiple touches on screen causes fps drop

I am trying to write a game in swift with spritesnode. I used the "touchesBegan" to shoot enemies and "touchesMoved" to move my ship. After a short minutes, the fps fall from 60 to almost 0 while the memory remains low (30 MB) and CPU is 100% almost all the time. I have about 30 nodes, 15 Draws. Here is the code of the "shooting" func fire() { laser = SKSpriteNode(imageNamed: "Laser") laser.name = "Laser" laser.size = CGSize(width: 20, height: 2) laser.position = ship.position if vitesse < 0 { let moveX = SKAction.moveBy (x: WidthScreen-ship.position.x, y: 0, duration: 0.5) let moveXDone = SKAction.removeFromParent() laser.run(SKAction.sequence([moveX, moveXDone])) } else { let moveX = SKAction.moveBy(x: -WidthScreen+ship.position.x, y: 0, duration: 0.5) let moveXDone = SKAction.removeFromParent() laser.run(SKAction.sequence([moveX, moveXDone])) } laser.physicsBody = SKPhysicsBody(rectangleOf: (laser.size)) laser.physicsBody?.categoryBitMask = PhysicsCategory.Laser laser.physicsBody?.collisionBitMask = PhysicsCategory.Invaders | PhysicsCategory.SmartInvaders | PhysicsCategory.UfoToSmart laser.physicsBody?.isDynamic = false laser.zPosition = 3 let soundAction = SKAction.playSoundFileNamed("Laser.wav", waitForCompletion: true); self.run(soundAction) self.addChild(laser) } and the code of the TouchesAction override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) { let touch : UITouch = touches.first! var touchLocation = touch.location(in: self) if touchLocation.y > 88*HeightScreen/100 { touchLocation.y = 88*HeightScreen/100 } if touchLocation.y < HeightScreen/15 { touchLocation.y = HeightScreen/15 } elevation = touchLocation.y } override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { /* Called when a touch begins */ if lifeArray.count>0{ fire() } } Someone would have an idea where the probleme come from ? Thank for your help Sincerely

Aucun commentaire:

Enregistrer un commentaire