1

I am writing an app with Xcode and swift. I am using SpriteKit's SKScene. I am having a super interesting error. I have a class Level1 and inside it, I have the touchesEnded method, and it works for about 2 or so clicks, and then it just stops. I have a simple print("hello world") in it, and it prints it twice, then stops. I don't really know what to attach for this error, so I have attached the method and the superclass method

import SpriteKit

class Level1: LevelBase {

    override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
        super.touchesEnded(touches, with: event)
        print("Hello world")
    }
}

and

import SpriteKit

class LevelBase: SKScene, SKPhysicsContactDelegate {

      override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
        for touch in touches {
            let location = touch.location(in: self)

            for node in nodes(at: location) {
                if node.name == "planet" {
                    moveAroundPlanet(planet: node as! SKSpriteNode)
                }
            }
        }
    }
}

I am adding Level1 from another scene using this

var scene = SKScene()
scene = Level1(fileNamed: "Level1")!
scene.scaleMode = .aspectFill
self.scene?.view?.presentScene(scene)

Let me know if any additional code is needed

Fluidity
  • 3,985
  • 1
  • 13
  • 34
  • have you checked if `touchesCancelled` is getting called in that case? – D4ttatraya Oct 19 '17 at 09:15
  • Something else is going on that removes the level1 scene from your game – Knight0fDragon Oct 19 '17 at 13:14
  • @D4ttatraya I tried it with `touchesBegan`, and `touchesCancelled`, and all exhibit the same behavior. @KnightOfDragon I tried a global search for `remove` and the only thing that comes up is when I remove a SHShapeNode, and when I remove an action from one of my other nodes. IS there any way it would be getting removed without the `remove` line? – Trevor Thomas Oct 19 '17 at 14:39
  • Doesnt have to be `remove` something else can take be taken over the view scene, or level1 never actually gets called. You aren't showing any code that replicates your problem. Create a MCVE (https://stackoverflow.com/help/mcve) and somebody will be better able to assist you. – Knight0fDragon Oct 20 '17 at 19:21
  • you are using question marks. how do we even know the scene is being presented? It may be self.nil.nil.presentScene, which does nothing. This is why MCVE is important, so that we may see exactly what steps you are taking. – Knight0fDragon Oct 24 '17 at 14:48

0 Answers0