如何使用鼠标滚轮进行缩放,我试试这个
if (currentMouseState.ScrollWheelValue < originalMouseState.ScrollWheelValue)
{
cameraPosition += new Vector3(0, -1, 0);
UpdateViewMatrix();
currentMouseState.ScrollWheelValue.Equals(0);
}
if (currentMouseState.ScrollWheelValue > originalMouseState.ScrollWheelValue)
{
cameraPosition += new Vector3(0, 1, 0);
UpdateViewMatrix();
currentMouseState.ScrollWheelValue.Equals(0);
}
Run Code Online (Sandbox Code Playgroud)
但即使我滚动一次,我仍然继续放大,我对XNA有点新意.请帮忙.
我有一个游戏,初始化为1920x1080.所有精灵,矢量等都特别正确放置,以匹配1920x1080类型.
我有一个enum,说明什么res,游戏被告知使用.1920x1080将成为标准.有没有办法,比方说,分辨率为1280x960,就这样:
有点像,在绘制事件之前,将屏幕捕获到a中Texture2D,并正确显示它以适合游戏窗口.
因为我仍然希望在12月之前创建一个简单的吃豆人克隆,我现在正在教自己C#以便使用XNA Game Studio 3.1,我找到了最好的答案,并提供了现成的文档来学习因为有点未来安全.
无论如何,问题来自我正在阅读的一本书,其中一个函数被声明为:
public void TransformVectorByReference()>
{
/* ...stuff... */
}
Run Code Online (Sandbox Code Playgroud)
我假设内部并不重要,因为编译器在函数声明中抱怨'>`符号.但是,多个函数被声明为这样,并且所有函数都抛出了类型的错误:
; 预期.
有人能告诉我这个功能是做什么的/指向我以前的SO问题,因为我没有通过搜索找到任何答案,因为我不知道该怎么称呼这个有趣的事情.
我得到这个代码片段的书是Sam的Microsoft XNA Game Studio 3.0.如果有人对本书有任何其他更好的选择,我会很高兴看到它们.
编辑:
我添加了一个示例函数,从三到五个函数,几乎相同,但一个使用>关键字.然而,有人指出,这可能不是作者的错,而是书的制作/错误纠正的方式.
public void TransformVectorByReference()
{
Matrix rotationMatrix = Matrix.CreateRotationY( MathHelper.ToRadians(45.0f) );
// Create a vector pointing the direction the camera is facing.
Vector3 transformedReference;
Vector3.Transform(ref cameraReference, ref rotationMatrix, out transformedReference);
// Calculcate the position the camera is looking at.
Vector3.Add(ref cameraPosition, ref transformedReference, out cameraTarget);
}
public void TransformVectorByReferenceAndOut()>
{
Matrix rotationMatrix = Matrix.CreateRotationY( MathHelper.ToRadians(45.0f) );
// …Run Code Online (Sandbox Code Playgroud) 我正在为Matlab组件构建一个接口层,该组件用于分析由我正在构建的单独.NET应用程序维护的数据.我正在尝试将.NET数据表序列化为数字数组,以传递给MATLAB组件(作为更通用的序列化例程的一部分).
到目前为止,我已经相当成功地传递了数值数据表,但是在尝试添加数据类型列时我遇到了麻烦DateTime.我到目前为止所做的是将值从填充DataTable到双数组中,因为MATLAB只关心双精度,然后直接转换为a MWNumericArray,它本质上是一个矩阵.
这是当前的代码;
else if (sourceType == typeof(DataTable))
{
DataTable dtSource = source as DataTable;
var rowIdentifiers = new string[dtSource.Rows.Count];
// I know this looks silly but we need the index of each item
// in the string array as the actual value in the array as well
for (int i = 0; i < dtSource.Rows.Count; i++)
{
rowIdentifiers[i] = i.ToString();
}
// convenience vars
int rowCount = dtSource.Rows.Count;
int colCount = dtSource.Columns.Count;
double[,] …Run Code Online (Sandbox Code Playgroud) using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace Project
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Texture2D myTexture;
Rectangle myRectangle;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This …Run Code Online (Sandbox Code Playgroud) 这个旧代码在 XNA 4.0 中不起作用。必须更改什么才能使代码在 XNA 4.0 中工作?
spriteBatch.Begin(SpriteBlendMode.AlphaBlend,SpriteSortMode.Immediate,SaveStateMode.None,Matrix.Identity);
graphics.GraphicsDevice.SamplerStates[0].MagFilter = TextureFilter.Point;
graphics.GraphicsDevice.SamplerStates[0].MinFilter = TextureFilter.Point;
graphics.GraphicsDevice.SamplerStates[0].MipFilter = TextureFilter.Point;
spriteBatch.End();
Run Code Online (Sandbox Code Playgroud)
我收到以下错误消息:
当前上下文中不存在“SpriteBlendMode”
当前上下文中不存在“SaveStateMode”“Microsoft.Xna.Framework.Graphics.SamplerState”不包含“MagFilter”的定义,并且没有接受“Microsoft.Xna.Framework”类型的第一个参数的扩展方法“MagFilter”。可以找到 Graphics.SamplerState'(您是否缺少 using 指令或程序集引用?)'Microsoft.Xna.Framework.Graphics.SamplerState' 不包含 'MinFilter' 的定义,并且没有接受第一个的扩展方法 'MinFilter'可以找到“Microsoft.Xna.Framework.Graphics.SamplerState”类型的参数(您是否缺少 using 指令或程序集引用?)“Microsoft.Xna.Framework.Graphics.SamplerState”不包含“MipFilter”的定义并且找不到接受类型为“Microsoft.Xna.Framework.Graphics.SamplerState”的第一个参数的扩展方法“MipFilter”(您是否缺少 using 指令或程序集引用?)
在您指出这个问题还有其他答案之前,我已经查看了这个问题或类似问题的大多数其他答案,但我还没有找到我需要的解决方案。
基本上我想要做的就是当圆/球与矩形碰撞时,我想确定碰撞发生在矩形的哪一侧。我想找出这一点,以便我可以执行更逼真的物理效果,例如,如果球击中矩形的顶部,则仅将其反转为 Y 速度……而不是两者兼而有之。
我已经尝试比较球和矩形的 X 和 Y 位置,甚至它们两个边界框的位置......即使球的底部与矩形顶部相交也进行测试......使用'if ball .boundingBox.Bottom >= rectangle.boundingBox.Top'。
我附上了一张图片来展示我想要达到的目标......以防万一它有点混乱,因为它没有详细......如果球从一侧进入,红色看起来像 v 是路径,我希望撞击时的运动以相反的方式行进,但这取决于矩形的一侧,我将不得不改变球速度的哪个分量......
仅供参考,我也看过向量归一化……我以前没有使用过它,所以请原谅我,如果可以用这个来解决这个问题……
非常感谢阅读
编辑因为我很匆忙,我使用了不同的图像代替......这仍然显示了我试图实现的行为,因为图中显示的物理是我希望球与另一个碰撞时的行为侧面......图像链接:http : //codeincomplete.com/posts/2011/6/12/collision_detection_in_breakout/bounce2.v283.png
我试图根据这里的注释创建一个自定义StringBuilder类.
这是我目前的代码:
class MyStringBuilder
{
public StringBuilder stringBuilder;
public String linkToStringBuilderString;
public MyStringBuilder(int maxCapacity)
{
stringBuilder = new StringBuilder(maxCapacity, maxCapacity);
linkToStringBuilderString = (String)stringBuilder.GetType().GetField("m_StringValue", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(stringBuilder);
}
};
Run Code Online (Sandbox Code Playgroud)
但是,应该获取内部StringBuilder字符串的永久链接的构造函数的最后一行给出了我的空引用编译错误,我不明白为什么.
我有以下变量:
[string]$eth_netmask = "ext_netmask"
[string]$ext_netmask = "255.255.252.0"
Run Code Online (Sandbox Code Playgroud)
$($eth_netmask)正在恢复ext_netmask.我期待255.255.252.0
我究竟做错了什么?
我在这里先向您的帮助表示感谢!
我想让我的矢量大小为3.我试过.reserve(3)但是没用.
vector<Microsoft::WRL::ComPtr<ID3D11Buffer>> asteroidIndexBuffers;
asteroidIndexBuffers.reserve(3);
Run Code Online (Sandbox Code Playgroud) 我试图这样做,以便当我的角色跳跃时,跳跃键被禁用,直到他的jumpHeight == 0(他又回到了地板上).C#中有一个简单的功能可以做到这一点吗?例如:
if (jumpHeight > 0)
{
keys.space == disabled
}
Run Code Online (Sandbox Code Playgroud)
提前致谢.
我正在为我的游戏开展响应式设计.我根据屏幕尺寸重新计算对象的位置.我正在做好的计算,但我的函数给我错误的结果总是返回0.我需要返回值为Int.
这里的代码:
public int rdnW(int a)
{
double b;
b = (a / 800 * 100);
return (int)(b * Widths / 100);
}
Run Code Online (Sandbox Code Playgroud)
有了断点,我看到b总是= 0; 在我的情况下a = 258.谢谢
我是xna的新手,我正在制作一个RPG.当我尝试按项目构建时,我得到错误:
1)当前上下文中不存在名称"component":
if (component is DrawableGameComponent)
((DrawableGameComponent)component).Visible = true;
Run Code Online (Sandbox Code Playgroud)
2)当前上下文中不存在名称"content":
LoadContent(content);
Run Code Online (Sandbox Code Playgroud)
在"组件"的错误在发现GameScreen类和"内容"的错误在发现启动画面类.
为什么会发生这些错误?它们是什么意思?谢谢.
Game1.cs
namespace myRPG
{
/// <summary>
/// Default Project Template
/// </summary>
public class Game1 : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
SpriteFont font;
//hold current state of the keyboard
KeyboardState keyboardState;
//hold previous state of the keyboard
KeyboardState oldKeyboardState;
//active screen will be set to either startScreen or actionScreen
GameScreen activeScreen;
StartScreen startScreen;
ActionScreen actionScreen;
CharScreen charScreen;
ClassScreen …Run Code Online (Sandbox Code Playgroud) c# ×11
xna ×10
xna-4.0 ×4
function ×2
xna-3.0 ×2
ado.net ×1
c++ ×1
division ×1
game-physics ×1
matlab ×1
powershell ×1
resolution ×1
string ×1
syntax ×1
variables ×1
vector ×1
xamarin.mac ×1