Luis Corvalan
Luis Corvalan

Reputation: 53

How to make a SKSpriteNode only appear by touch?

How to make a SKSpriteNode only work by touching the screen? I have already written var main = SKSpriteNode() and main = self.childNode(withName: "main") as! SKSpriteNode

Upvotes: 1

Views: 49

Answers (1)

Confused
Confused

Reputation: 6278

There's three parts to this process.

  1. Getting the touch. This is probably done in the GameScene's touchesBegan, in which you need to find the position of the touch.

  2. Having a Sprite to create. This can be part of a function that creates a SKSprite in the GameScene's top level, so you can call it, or it could be a class of your own that you instance on the touch.

  3. Creating, and then Adding the child to the scene.

I think it's the last part, adding the child to the scene, that you might be missing.

Upvotes: 3

Related Questions