C# 单游戏-切割场景方法?
我想创建的内容 因此,我正在使用Monogame构建一个2D冒险游戏,在游戏开始时,我想使用3个图像来显示前面的故事情节,有点像一个介绍剪辑场景,因此每个图像显示游戏中故事开始的不同快照 我希望它如何工作 我希望它只是显示一个图像,然后被第二个图像重叠,然后是第三个图像,每个图像之间有大约3秒的停顿(根本不需要考虑过渡) 我向所有读者提出的问题C# 单游戏-切割场景方法?,c#,.net,visual-studio,xna,monogame,C#,.net,Visual Studio,Xna,Monogame,我想创建的内容 因此,我正在使用Monogame构建一个2D冒险游戏,在游戏开始时,我想使用3个图像来显示前面的故事情节,有点像一个介绍剪辑场景,因此每个图像显示游戏中故事开始的不同快照 我希望它如何工作 我希望它只是显示一个图像,然后被第二个图像重叠,然后是第三个图像,每个图像之间有大约3秒的停顿(根本不需要考虑过渡) 我向所有读者提出的问题 我想知道,什么是最好的方法来实现这一点,使它开始在我的游戏开始?我正在考虑在Premier Pro上制作剪接场景,在那里它只是一个播放的视频,但是我不确
我想知道,什么是最好的方法来实现这一点,使它开始在我的游戏开始?我正在考虑在Premier Pro上制作剪接场景,在那里它只是一个播放的视频,但是我不确定是否有更好的选择我只想知道实现类似目标的最简单方法是什么。最好用一两句话准确地定义您想要的内容,这样您就可以简单地编写代码。我个人将Cutsecene定义为:“从黑屏淡入的图像列表,停留一段时间,然后淡入黑色。您可以通过按单个键盘按钮(如空格键)跳过一个图像。”这意味着我将包括计时器和图像。这样我就知道了每张图片和整个幻灯片的完整播放时间 我有一些旧代码可能会帮助你。此代码获取要显示的图像列表、淡入时间、站立时间和淡出时间。通过将淡入/淡出为黑色效果切换为带重叠效果的淡入,可以很容易地转换为您想要的效果 首先,这里是单屏幕类:
using System;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
namespace F.U.N
{
public class SplashScreen
{
public enum Status
{
Ready,
FadingIn,
Waiting,
FadingOut,
NotReady
}
private Status currentStatus;
public Status CurrentStatus { get { return currentStatus; } }
private Texture2D image;
private Color color;
private byte fade;
private float timer,
fadeInTime,
waitTime,
fadeOutTime;
private float startToWaitTime { get { return fadeInTime; } }
private float startToFadeOutTime { get { return fadeInTime + waitTime; } }
private float startToEndTime { get { return fadeInTime + waitTime + fadeOutTime; } }
public SplashScreen(Texture2D image, float fadeInTime, float waitTime, float fadeOutTime)
{
float min = 0.1f;
this.image = image;
this.fadeInTime = Math.Max(fadeInTime, min);
this.waitTime = Math.Max(waitTime, min);
this.fadeOutTime = Math.Max(fadeOutTime, min);
Prepare();
}
public void Prepare()
{
fade = 0;
timer = 0;
color = new Color(fade, fade, fade);
currentStatus = Status.Ready;
}
public void Update(GameTime gt)
{
//CALCULATE ALPHA & status
if (timer < startToWaitTime)
{
fade = (byte)((byte.MaxValue * timer) / startToWaitTime);
if (currentStatus != Status.FadingIn) currentStatus = Status.FadingIn;
}
else if (timer < startToFadeOutTime)
{
if (color.A < byte.MaxValue) color.A = byte.MaxValue;
if (currentStatus != Status.Waiting) currentStatus = Status.Waiting;
}
else if (timer < startToEndTime)
{
fade = (byte)(byte.MaxValue - ((byte.MaxValue * (timer - startToFadeOutTime)) / fadeOutTime));
if (currentStatus != Status.FadingOut) currentStatus = Status.FadingOut;
}
else
{
fade = byte.MinValue;
if (currentStatus != Status.NotReady) currentStatus = Status.NotReady;
}
//UPDATE COLOR AND TIME
color = new Color(fade, fade, fade);
timer += (float)gt.ElapsedGameTime.TotalSeconds;
}
public void Draw(SpriteBatch sp)
{
sp.Draw(image, new Vector2(), color);
}
public void End()
{
currentStatus = Status.NotReady;
}
}
}
SplashScreenManager构造函数的注释:GContent.Textures(路径)
的目标是尝试从该文件夹加载所有图像。此函数如下所示:
public static List<Texture2D> Textures(string folderPath)
{
if (!folderPath.StartsWith(@"\")) folderPath = @"\" + folderPath;
List<string> paths = Directory.GetFiles(Help.RootDir(Content.RootDirectory) + folderPath).ToList();
List<Texture2D> images = new List<Texture2D>();
foreach (string s in paths)
{
if (s.EndsWith(".xnb"))
images.Add(Texture(s.Replace(Content.RootDirectory, "").Replace(".xnb", "")));
}
return images;
}
public static string RootDir(string s)
{
return s.Substring(0, s.LastIndexOf(@"\"));
}
public enum GameState
{
Initialize,
Menu,
Level,
MapMaker
}
public GameState currentGameState = GameState.Initialize;
通过这种方式,您可以在一个文件夹中保存所有飞溅图像。实际上,如何管理资源取决于你自己。这是一种非常简单的方法,具有一些强大的功能。尝试在后台使用旧的sony play station sound进行测试,并将这些参数用于SSM:SSM=new SplashScreenManager(您的splash图像列表,3、1、3)
。看起来和听起来都很棒。如果这对你有帮助,那就竖起大拇指
编辑:
我没有在游戏开始时告诉你怎么玩这个。使用枚举定义游戏状态,使用单个变量存储该信息,如下所示:
public static List<Texture2D> Textures(string folderPath)
{
if (!folderPath.StartsWith(@"\")) folderPath = @"\" + folderPath;
List<string> paths = Directory.GetFiles(Help.RootDir(Content.RootDirectory) + folderPath).ToList();
List<Texture2D> images = new List<Texture2D>();
foreach (string s in paths)
{
if (s.EndsWith(".xnb"))
images.Add(Texture(s.Replace(Content.RootDirectory, "").Replace(".xnb", "")));
}
return images;
}
public static string RootDir(string s)
{
return s.Substring(0, s.LastIndexOf(@"\"));
}
public enum GameState
{
Initialize,
Menu,
Level,
MapMaker
}
public GameState currentGameState = GameState.Initialize;
在游戏开始时,设置currentGameState=GameState.Initialize代码>,加载ssm,并在更新中检查ssm(启动屏幕管理器)是否已结束播放。如果有,请将currentGameState
更改为GameState.菜单
,并在Update
方法中使用开关
功能,这样您就知道您的游戏当前处于哪个游戏状态,从而知道要更新什么。在上面的代码中有这样的例子,但我没有写过,这就是编辑的原因