且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

统一运动触摸

更新时间:2023-02-01 22:55:03

使用轴触摸开关,这将有点困难。我建议阅读有关Touchscript( http://interactivelab.github.io/TouchScript/ )以及如何API的工作一般。你会需要做的就是当玩家触摸屏幕,你缓存联系,当他们碰你直呼其触摸比较其当前位置测量运动的方向。 。通过这样做,你可以刷卡路线

Switching this from using axis to touch will be a bit difficult. I recommend reading about Touchscript (http://interactivelab.github.io/TouchScript/) and how the API works in general. What you're going to need to do is when the player touches the screen, you cache that touch and while they're touching you measure the direction of the movement by comparing their first touch to their current position. By doing this you can get swipe directions.

像这样的东西可以让你开始:

Something like this could get you started:

public void OnTouchBegin( object sender, TouchEventArgs e ){
    foreach( TouchPoint point in e.TouchPoints ){
        firstTouchPosition = new Vector2( point.Position.x, point.Position.y );
    }
}

public void OnTouchContinue( object sender, TouchEventArgs e ){
    foreach( var point in e.TouchPoints ){
        secondTouchPosition  = new Vector2( point.Position.x, point.Position.y );
        currentTouchMovement = new Vector2( ( secondTouchPosition.x - firstTouchPosition.x ),
        ( secondTouchPosition.y - firstTouchPosition.y ));
        currentTouchMovement.Normalize( );
    }
}

public void OnTouchEnd( object sender, TouchEventArgs e ){
    hasTouchEnded = true;
}

和你需要一些自定义代码来确定X和Y轴方向与触摸输入相对应。另外要小心屏幕坐标和游戏中的坐标为它们之间的区别相当多。这看起来令人生畏在第一,但也有一些工作,我保证它不是太糟糕了!希望这有助于!

And you'll need some custom code to determine the X and Y axis direction corresponds with the touch input. Also be careful about screen coordinates and in-game coordinates as they differ quite a bit. This looks daunting at first, but with some work I promise its not too bad! Hope this helps!