# Multiple touches on screen causes fps drop

**URL:** <https://forums.kodeco.com/t/multiple-touches-on-screen-causes-fps-drop/16685>\
**Category:** Sprite Kit\
**Created:** [June 29, 2016, 12:23pm UTC](https://forums.kodeco.com/t/multiple-touches-on-screen-causes-fps-drop/16685 "2016-06-29T12:23:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![oltes](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/oltes/32/35909_2.png) [@oltes](https://forums.kodeco.com/u/oltes)\
**Post date:** [June 29, 2016, 12:23pm UTC](https://forums.kodeco.com/t/multiple-touches-on-screen-causes-fps-drop/16685/1 "2016-06-29T12:23:31Z")

</div>

Hi everybody,  
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.

Someone would have an idea where the probleme come from ?  
Thank for your help

Sincerely

here the code of “fire” func and “touchesmoved and began” func

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)

```

}

override func touchesMoved(\_ touches: Set, 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, with event: UIEvent?) {  
/\* Called when a touch begins \*/  
if lifeArray.count\>0{  
fire()  
}  
}

---

<div class="post-metadata">

**Author:** ![marciokoko](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/marciokoko/32/32922_2.png) [@marciokoko](https://forums.kodeco.com/u/marciokoko)\
**Post date:** [June 30, 2016, 5:12pm UTC](https://forums.kodeco.com/t/multiple-touches-on-screen-causes-fps-drop/16685/2 "2016-06-30T17:12:06Z")

</div>

Do you know how to use Instruments?

30 nodes is a bit but do you have any particle emitters?

You need to use Instruments to find out which node is hogging resources.

---

<div class="post-metadata">

**Author:** ![oltes](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/oltes/32/35909_2.png) [@oltes](https://forums.kodeco.com/u/oltes)\
**Post date:** [June 30, 2016, 5:43pm UTC](https://forums.kodeco.com/t/multiple-touches-on-screen-causes-fps-drop/16685/3 "2016-06-30T17:43:52Z")

</div>

Hi, thank you for your answers.  
I know use Instruments but not interpret it.  
I use emitters only for ship and invaders explosions.

When i change “touchesmoved” and “touches began” by automatics action (accelerometer data and automatics fire) fps drop but not very quick.  
here is a screen copy of instruments recording, can you help me ?

 ![](https://raywenderlich-com-v3-forums.s3.amazonaws.com/original/3X/6/4/64c77f8c47ddcb74c846ce0b4d4eb3d5400d0cfd.png)

thank you very much
