【问题标题】:Moving a slider to change resolution移动滑块以更改分辨率
【发布时间】:2013-12-11 14:20:33
【问题描述】:

我对滑动图像有一个小问题,可以更改图像以在其右侧显示不同的分辨率。当相应地设置分辨率时,用户必须按下一个确定框才能更改分辨率。当我在此处显示的背景上移动滑块时:

滑块的工作原理是让滑块停止在最大和最小 int 处。由于图像位于图像的左上角,因此最小值(女巫在最右边)位于从高白线到左侧的像素上,最大值也是如此。我在重绘和放置图像时使用了 2 个类,一个 Options 类和主类 Game1Options 类拥有一个 draw 方法并将其移至主类以在屏幕上绘制。

Options.cs(绘制方法):

public static void Draw(SpriteBatch spriteBatch)
{
    spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullCounterClockwise);
    spriteBatch.Draw(Images.Res1, res, Color.White);
    spriteBatch.Draw(Images.Res2, res, Color.White);
    spriteBatch.Draw(Images.Res3, res, Color.White);
    spriteBatch.Draw(Images.Res4, res, Color.White);
    spriteBatch.Draw(Images.Res5, res, Color.White);
    spriteBatch.Draw(Images.Res6, res, Color.White);
    spriteBatch.Draw(Images.Res7, res, Color.White);
    spriteBatch.Draw(Images.Res8, res, Color.White);
}

我想在指针处于正确位置时调用这些图像,因此我将上面的代码编辑为如下所示:

public static void Draw(SpriteBatch spriteBatch)
{
    spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullCounterClockwise);
    if (slide3.X >= options.resStart && slide3.X <= options.resEnd)
        spriteBatch.Draw(Images.Res1, res, Color.White);
    else if (slide3.X >= options.res2Start && slide3.X <= options.res2End)
        spriteBatch.Draw(Images.Res2, res, Color.White);
    else if (slide3.X >= options.res3Start && slide3.X <= options.res3End)
        spriteBatch.Draw(Images.Res3, res, Color.White);
    else if (slide3.X >= options.res4Start && slide3.X <= options.res4End)
        spriteBatch.Draw(Images.Res4, res, Color.White);
    else if (slide3.X >= options.res5Start && slide3.X <= options.res5End)
        spriteBatch.Draw(Images.Res5, res, Color.White);
    else if (slide3.X >= options.res6Start && slide3.X <= options.res6End)
        spriteBatch.Draw(Images.Res6, res, Color.White);
    else if (slide3.X >= options.res7Start && slide3.X <= options.res7End)
        spriteBatch.Draw(Images.Res7, res, Color.White);
    else if (slide3.X >= options.res8Start && slide3.X <= options.res8End)
        spriteBatch.Draw(Images.Res8, res, Color.White);
    else
        spriteBatch.DrawString(Game1.font1, "ERROR!!!", new Vector2(res.X, res.Y), Color.White);
}

如果我运行程序,图像会输出“错误”。我想这个问题将是我缺乏经验的一个非常愚蠢的错误,并且仍在学习。

【问题讨论】:

  • 我可以做的事情是创建一个字符串值并使其更新,以便更新执行 if else 语句,然后让它如果字符串等于我输入的名称,然后绘制图像。

标签: c# image xna draw


【解决方案1】:

我已经解决了这个问题,我需要将 if else 语句移到主函数的更新方法中,在那里我可以简单地将字符串复制过来。我宁愿将其保留在 Options 类中,而不是将其添加到主类中。

if (StartUp.Options.slide3.X >= options.resStart && StartUp.Options.slide3.X <= options.res2Start)
    StartUp.Options.resLocation = "Res1";
else if (StartUp.Options.slide3.X >= options.res2Start && StartUp.Options.slide3.X <= options.res3Start)
    StartUp.Options.resLocation = "Res2";
else if (StartUp.Options.slide3.X >= options.res3Start && StartUp.Options.slide3.X <= options.res4Start)
    StartUp.Options.resLocation = "Res3";
else if (StartUp.Options.slide3.X >= options.res4Start && StartUp.Options.slide3.X <= options.res5Start)
    StartUp.Options.resLocation = "Res4";
else if (StartUp.Options.slide3.X >= options.res5Start && StartUp.Options.slide3.X <= options.res6Start)
    StartUp.Options.resLocation = "Res5";
else if (StartUp.Options.slide3.X >= options.res6Start && StartUp.Options.slide3.X <= options.res7Start)
    StartUp.Options.resLocation = "Res6";
else if (StartUp.Options.slide3.X >= options.res7Start && StartUp.Options.slide3.X <= options.res8Start)
    StartUp.Options.resLocation = "Res7";
else if (StartUp.Options.slide3.X >= options.res8Start && StartUp.Options.slide3.X <= options.res8End)
    StartUp.Options.resLocation = "Res8";
else
    StartUp.Options.resLocation = "Error";

【讨论】:

    猜你喜欢
    • 2014-08-24
    • 1970-01-01
    • 1970-01-01
    • 2017-10-19
    • 2013-09-30
    • 1970-01-01
    • 2015-04-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多