【问题标题】:How can I check the current orientation of my windows phone device?如何检查我的 windows phone 设备的当前方向?
【发布时间】:2014-06-25 21:30:21
【问题描述】:

我需要知道播放器何时切换设备的方向。因此,我使用这个事件,但我总是这个错误信息。怎么了?

this.OrientationChanged += OrientationChanged();

方法 'OrientationChanged' 没有重载需要 0 个参数

如何在 MonoGame Windows Phone 8 游戏中使用此事件?

我在 Game1.cs 中使用如下代码:

this.OrientationChanged += OrientationChanged();

void OrientationChanged(object sender, OrientationChangedEventArgs e)
{
    if (e.Orientation == PageOrientation.LandscapeLeft)
    {

    }
}

我的项目:https://www.dropbox.com/s/qa1ty2ydo1hqfwn/MonogameFarseerDemo.rar

【问题讨论】:

    标签: c# xna monogame


    【解决方案1】:

    更改以下行:

    this.OrientationChanged += OrientationChanged();
    

    用这个:

    this.OrientationChanged += OnOrientationChanged;
    
    void OnOrientationChanged(object sender, OrientationChangedEventArgs e)
    {
        if (e.Orientation == PageOrientation.LandscapeLeft)
        {
    
        }
    }
    

    【讨论】:

    • 它不工作。我更改了它,但现在我收到此错误消息:无法分配给“OrientationChanged”,因为它是“方法组”
    • 请再次检查,问题是OrientationChanged名称既用于事件又用于处理程序方法。
    • 它不工作。现在我收到此错误消息:“MonogameFarseerDemo.Game1”不包含“OrientationChanged”的定义,并且找不到接受“MonogameFarseerDemo.Game1”类型的第一个参数的扩展方法“OrientationChanged”
    • OrientationChanged 事件发生在 GameWindow,而不是 Game。使用this.Window.OrientationChanged += OnOrientationChanged;
    • @Cole Campbell 我更改了它,但现在我收到此错误消息:“OnOrientationChanged”没有重载匹配委托“System.EventHandler
    猜你喜欢
    • 1970-01-01
    • 2014-09-10
    • 1970-01-01
    • 2014-10-26
    • 2020-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多