如何使用Swift在操场上获取用户交互事件

时间:2021-08-08 11:50:10

I'm trying to prototype a game with SpriteKit with Swift in a playground.

我正试图在操场上用SwiftKit和Swift对游戏进行原型设计。

I'm having difficulties getting the user touch callbacks to work.

我无法让用户触摸回调工作。

Here's what I am trying :

这是我正在尝试的:

let view:SKView = SKView(frame: CGRectMake(0, 0, 320, 586))
XCPShowView("Live view", view)

class PrototypeScene: SKScene {

    override func didMoveToView(view: SKView) {
        self.userInteractionEnabled = true
    }

    override func touchesBeganWithEvent(event: NSEvent!)
    {
        println("Hello touches")   
    }
}

let scene:PrototypeScene = PrototypeScene(size: CGSizeMake(320, 586))
scene.scaleMode = SKSceneScaleMode.AspectFit

view.presentScene(scene)

I'm not getting the callbacks for the responder chain. How would one enable this?

我没有得到响应者链的回调。如何实现这一目标?

2 个解决方案

#1


4  

User interaction is not available in Playgrounds (Source: WWDC).

Playgrounds中没有用户交互(来源:WWDC)。

#2


0  

User interactions in Playground are not available in Xcode 7.2 and below

Playground中的用户交互在Xcode 7.2及更低版本中不可用

#1


4  

User interaction is not available in Playgrounds (Source: WWDC).

Playgrounds中没有用户交互(来源:WWDC)。

#2


0  

User interactions in Playground are not available in Xcode 7.2 and below

Playground中的用户交互在Xcode 7.2及更低版本中不可用