TouchesBeganWithEvent 在 SKScene 中未被调用



我在 SKScene 中遇到触摸事件的问题,当我在场景 :( 中触摸精灵时,这些事件没有被调用

这是我的代码

public class FallingObjectsScene : SKScene
{
    public override void DidMoveToView(SKView view)
    {
        base.DidMoveToView(_view);
        UserInteractionEnabled = true;
        Image = new SKSpriteNode();
        Image.Position = new CGPoint(labelXpostion, skView.Bounds.GetMaxY());
        Image.Texture = imageTexture.Texture;
        Image.Size = new CGSize(60, 60);
        Image.Speed = 3.01f;
        Image.AnchorPoint = new CGPoint(x: 0.5, y: 0.5);
        AddChild(Image);
    }
 }
 public override void TouchesBeganWithEvent(NSEvent theEvent)
 {
    base.TouchesBeganWithEvent(theEvent);
    var point = theEvent.LocationInNode(this);
    var touchNode = GetNodeAtPoint(point);
    try
    {
        //... some code
    }
    catch (Exception exception)
    {
        LoggingManager.Error(exception);
        ClearScreenTouches();
    } 
 }

任何人都可以帮助解决这个问题,谢谢。

你的语法看起来很奇怪,在 Xcode 8.2.1 和 Swift 3 上,它应该看起来像:

class MenuScene: SKScene {
    override init(){...}
    override func didMove(to view: SKView) {
       ...
    }
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        for touch in (touches ){
            let location = touch.location(in: self)
            let touchNode = atPoint(location)
            ...
        }
    }
}

最新更新