Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# XNA框架:操纵屏幕亮度_C#_.net_Windows Phone 7_Xna_Xna 4.0 - Fatal编程技术网

C# XNA框架:操纵屏幕亮度

C# XNA框架:操纵屏幕亮度,c#,.net,windows-phone-7,xna,xna-4.0,C#,.net,Windows Phone 7,Xna,Xna 4.0,我正在为XNA框架的游戏做一个项目 我正在使用选项菜单屏幕类向用户显示不同的游戏选项/设置 我在屏幕上添加了两个UP和DOWN按钮(Texture2D),可以增加或降低屏幕亮度 我无法找到操作屏幕亮度所需的逻辑 如果你能为我指出正确的方向,我将不胜感激 以下是相关代码: 类选项菜单筛选:菜单筛选 { SpriteBatch SpriteBatch; 亮度; 纹理2D明亮度上升; 纹理2D亮度下降; ContentManager; 公共选项菜单筛选():基本(“选项”) { 亮度=新菜单(“亮度

我正在为XNA框架的游戏做一个项目

我正在使用
选项菜单屏幕
类向用户显示不同的游戏选项/设置

我在屏幕上添加了两个
UP
DOWN
按钮(
Texture2D
),可以增加或降低屏幕亮度

我无法找到操作屏幕亮度所需的逻辑

如果你能为我指出正确的方向,我将不胜感激

以下是相关代码:


类选项菜单筛选:菜单筛选
{
SpriteBatch SpriteBatch;
亮度;
纹理2D明亮度上升;
纹理2D亮度下降;
ContentManager;
公共选项菜单筛选():基本(“选项”)
{
亮度=新菜单(“亮度”);
菜单项。添加(亮度);
}
公共覆盖无效加载内容()
{
if(contentManager==null)
{
contentManager=新的contentManager(ScreenManager.Game.Services,“内容”);
}
brightnessUp=contentManager.Load(“handup”);
brightnessDown=contentManager.Load(“移交”);
}
公共覆盖无效绘制(游戏时间游戏时间)
{
spriteBatch=ScreenManager.spriteBatch;
var亮度下降位置=
新矢量2(亮度.位置.X-50,亮度.位置.Y-12);
var亮度上升=
新矢量2(亮度.Position.X
+亮度.GetWidth(this)+8,亮度.Position.Y-12);
spriteBatch.Begin();
spriteBatch.Draw(亮度下降,
新矩形((int)brightnessDownPosition.X,(int)brightnessDownPosition.Y,
30,30),颜色为白色;
spriteBatch.Draw(亮度上升,
新矩形((int)brightnessUpPosition.X,(int)brightnessUpPosition.Y,
30,30),颜色为白色;
spriteBatch.End();
基础。抽签(游戏时间);
}
公共覆盖无效更新(游戏时间、bool otherscreen焦点、bool coveredByOtherScreen)
{
更新(游戏时间,其他屏幕有焦点,被其他屏幕覆盖);
foreach(TouchPanel.GetState()中的触摸位置t)
{
如果(t.Position.X>=brightnessDown.Bounds.Left
&&t.Position.X=亮度down.Bounds.Top
&&t.Position.X=brightnessUp.Bounds.Left
&&t.Position.X=brightnessUp.Bounds.Top
&&t.Position.X,有几种方法可以实现:

  • 使用
  • 使用黑色纹理和alpha透明度
  • 为场景中的所有对象调整纹理上的材质和/或灯光
  • 使用像素着色器重新计算每像素颜色
第一个选项是最简单的,但有一些缺点(设置时会产生难看的图形效果-大多数效果只是在“选项”菜单中),而且并不总是受支持

您可以使用和来确定它是否受支持,如果不受支持,则返回到其他方法

编辑

在Windows Phone 7上

该网站(目前已被破坏,但如果你在谷歌上搜索它,你可以找到一个缓存副本)建议你使用全屏四边形和alpha混合方法,并使用以下特定混合模式:

Brightness: source = ZERO, dest = SOURCECOLOR
Contrast: source = DESTCOLOR, dest = SOURCECOLOR
下面是一些代码(从那篇文章中偷来的):

//在游戏类中:
纹理2d白色纹理;
//在LoadContent中:
白色纹理=新纹理2d(图形设备,1,1);
SetData(新颜色[]{Color.White});
//在适当的类别中(游戏类别?不确定…):
亮度;
内部对比;
混合状态亮度混合;
混合状态;
//在初始化中:
亮度=255;
对比度=128;
brightnessBlend=新的混合状态();
brightnessBlend.ColorSourceBlend=brightnessBlend.AlphaSourceBlend=Blend.Zero;
brightnessBlend.ColorDestinationBlend=brightnessBlend.AlphaDestinationBlend=Blend.SourceColor;
对比混合=新混合状态();
ContractBlend.ColorSourceBlend=ContractBlend.AlphaSourceBlend=Blend.DestinationColor;
ContractBlend.ColorDestinationBlend=ContractBlend.AlphaDestinationBlend=Blend.SourceColor;
//抽签:
spriteBatch.Begin(SpriteSortMode.Immediate,brightnessBlend);
绘制(白色纹理,新矩形(0,0,480,800),新颜色(亮度,亮度,亮度,255));
spriteBatch.End();
spriteBatch.Begin(SpriteSortMode.Immediate、ControlBlend);
绘制(白色纹理,新矩形(0,0480800),新颜色(对比度,对比度,对比度,255));
spriteBatch.End();
GraphicsDevice.BlendState=BlendState.不透明;

我也发现了相同的代码,问题是如何在继承自GameScreen类的OptionsMenuScreen类中实现它。GameScreen类没有与上面粘贴的Game1.cs类模板相同的方法。那么如何让这两个类协同工作,它们都有我需要使用的方法?@Mash:S对不起,没有安装XNA,所以我无法检查它。如果你可以从一个实例访问另一个实例,你可以很容易地用公共属性/方法弥补差距。我想你应该公开这些亮度和对比度属性,并将其余属性留在游戏类中,因为它不需要直接访问。如果我建议您添加自己的答案,以显示您如何帮助有相同问题的人。@Mash:从game类访问screen类的一种方法是通过构造函数传递game类。这可能只有在手动从游戏类中的一些代码构造screen类。再说一次,我没有安装XNA,并且已经有2年没有接触过它了,所以我记不清了。。。
Brightness: source = ZERO, dest = SOURCECOLOR
Contrast: source = DESTCOLOR, dest = SOURCECOLOR
// In your game class:

Texture2D whiteTexture;

// In LoadContent:

whiteTexture = new Texture2D(GraphicsDevice, 1, 1);
whiteTexture.SetData<Color>(new Color[] { Color.White });

// In the appropriate class (the game class? not sure...):

int brightness;
int contrast;

BlendState brightnessBlend;
BlendState contrastBlend;

// In Initialize:

brightness = 255;
contrast = 128;

brightnessBlend = new BlendState();
brightnessBlend.ColorSourceBlend = brightnessBlend.AlphaSourceBlend =  Blend.Zero;
brightnessBlend.ColorDestinationBlend = brightnessBlend.AlphaDestinationBlend = Blend.SourceColor;

contrastBlend = new BlendState();
contrastBlend.ColorSourceBlend = contrastBlend.AlphaSourceBlend = Blend.DestinationColor;
contrastBlend.ColorDestinationBlend = contrastBlend.AlphaDestinationBlend = Blend.SourceColor;

// In Draw:

spriteBatch.Begin(SpriteSortMode.Immediate, brightnessBlend);
spriteBatch.Draw(whiteTexture, new Rectangle(0, 0, 480, 800), new Color (brightness, brightness, brightness, 255));
spriteBatch.End();

spriteBatch.Begin(SpriteSortMode.Immediate, contrastBlend);
spriteBatch.Draw(whiteTexture, new Rectangle(0, 0, 480, 800), new Color(contrast, contrast, contrast, 255));
spriteBatch.End();

GraphicsDevice.BlendState = BlendState.Opaque;