touch event in spritekit

Asked 1 months ago, Updated 1 months ago, 5 views

I'd like to make a simple game and erase the node (enemy) with a touch event, but I don't know how to do it.Thank you for your cooperation.

override functouchesBegan(touches:Set<UITouch>, withEvent:UIEvent?){

    // Enable Multi-Touch
    self.view?.multipleTouchEnabled=true

    // We're going to take out one piece of information.
    for touch intouches {
        // We're going to take a position on the scene.
        let location = touch.locationInNode(self)
        // look at the node in the position
        let touchNodes=self.nodesAtPoint(location)
        // examine each node
        US>fortNode into touchNodes{
            // If the node you touch is an enemy, erase it.
            ifNode==mySprite
            {
                mySprite.removeFromParent()

                // indicate the location of
                print(tNode)
            }
        }
    }
}

ios

2022-09-30 13:56

1 Answers

Only removeFromParent() disappears the node.
If the code you provided doesn't go away, I think there is a problem where there is no presentation.

*In order to eliminate duplicate questions, you may want to delete the other question as well as leave the other question.


2022-09-30 13:56

If you have any answers or tips


© 2022 OneMinuteCode. All rights reserved.