我决定将我的游戏从窗口模式转移到全屏模式,这是我面临的第一个问题。我正在寻找一种根据屏幕分辨率调整所有精灵大小的方法。我的背景现在在(0, 0)坐标中,但我需要让它和所有精灵以某种固定的纵横比(16:9首选)进行缩放。并将它们调整到背景被拉伸以填充屏幕的那部分。而且不多也不少。
我查看了一些在线教程,但我真的无法理解他们使用的概念。你能解释一下你会怎么做吗?我使用 a 读取RenderTarget2D并将其传递给spriteBatch.Begin()调用,具有某种效果,但必须有更多代码。
我不是要支持分辨率更改选项,而是要使精灵适应当前分辨率。
stringto 的映射int工作正常。
std::map<std::string, int> // working
Run Code Online (Sandbox Code Playgroud)
但我想将C-style字符串映射到int
例如:
char A[10] = "apple";
map<char*,int> mapp;
mapp[A] = 10;
Run Code Online (Sandbox Code Playgroud)
但是当我尝试访问映射到“apple”的值时,我得到的是一个垃圾值而不是 10。为什么它的行为与std::string?
我有一个实现的类IDisposable,因为它使用Bitmap来自GDI +的图像资源(类).我用它来包装所有那些花哨的LockBits/ UnlockBits.它工作正常,无论是我打电话Dispose()还是using声明.
但是,如果我让程序在没有处理的情况下终止,我会得到一个System.AccessViolationException.直观地说,我认为GC将以Dispose与我相同的方式调用,并且该对象将优雅地释放资源,但这不是发生的事情.为什么?
这是IDisposable代码:
private bool _disposing = false;
~QuickBitmap() {
Dispose(false);
}
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool safeDispose) {
if (_disposing)
return;
SaveBits(); // private wrapper to UnlockBits
bytes = null; // byte[] of the image
bmpData = null; // BitmapData object
if (safeDispose && bm != null) {
bm.Dispose(); // Bitmap object
bm = null; …Run Code Online (Sandbox Code Playgroud) 我试图了解如何以正确的方式使用自定义异常.
我已经多次使用过try/catch但是从来没有说过何时使用自己的类关闭异常.我已经阅读并观看了许多教程,但我无法理解这一点.
这是我的CustomException班级:
[Serializable]
class CustomException : FormatException
{
/// <summary>
/// Just create the exception
/// </summary>
public CustomException()
: base() {
}
/// <summary>
/// Create the exception with description
/// </summary>
/// <param name="message">Exception description</param>
public CustomException(String message)
: base(message) {
}
/// <summary>
/// Create the exception with description and inner cause
/// </summary>
/// <param name="message">Exception description</param>
/// <param name="innerException">Exception inner cause</param>
public CustomException(String message, Exception innerException)
{
}
}
Run Code Online (Sandbox Code Playgroud)
这是我尝试使用它的地方:
/// <summary> …Run Code Online (Sandbox Code Playgroud) c# ×3
c++ ×1
dictionary ×1
exception ×1
fullscreen ×1
gdi+ ×1
monogame ×1
scale ×1
stl ×1
string ×1