Swift-Get screen click coordinates under All objects (Spritekit game development)

Source: Internet
Author: User
Tags spritekit

for the click response of the object element in the scene, we can process it uniformly within the Touchesbegan () method of the scene.

Skscene in Touchesbegan () is a way to respond to a screen click, where we can first get all the objects under the click, and then filter out the desired object and then call the method of the object.

123456789101112131415161718192021222324252627 import SpriteKitclass GameScene: SKScene {        //当切换到这个场景视图后    override func didMoveToView(view: SKView) {    }        //响应屏幕点击的方法    override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {                for touch:AnyObject in touches{            //获取点击的坐标            let location = touch.locationInNode(self)            //该坐标下所有的对象            var arrObject = self.nodesAtPoint(location)            //找出为HanggePoint类型的对象            for p in arrObject {                let point = p as? HanggePoint                //如果该对象不为nil,就调用该对象方法                if point != nil {                    point.onTouch()                }            }                    }    }}

Swift-Get screen click coordinates under All objects (Spritekit game development)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.