2017-02-09 84 views
1

我有在SKScene觸摸事件的問題,這些都沒有得到所謂的,當我在現場:(TouchesBeganWithEvent沒有得到所謂的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(); 
    } 
} 

誰能幫助爲了解決這個問題, 感謝

回答

0

你的語法看起來奇怪,上的Xcode 8.2.1 &斯威夫特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) 

      ... 
     } 
    } 
} 
+0

感謝您的回覆,我遵循上述相同的代碼,我使用Xamarin技術,技術並不重要,但該方法未被調用。 – Mounika

+0

從你發佈的代碼,它看起來好像你的touchesBegan功能,而不是你的類定義,這是陳是在什麼, –

+0

@SteveIves是的,但touchesBegan功能不顯示在我的Xamarin技術:(這就是爲什麼我使用鼠標事件。 – Mounika

相關問題