touch event in spritekit

Asked 2 years ago, Updated 2 years ago, 43 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


© 2024 OneMinuteCode. All rights reserved.