Tag: xna

每像素碰撞 – 代码说明

我目前正在尝试理解每像素碰撞检测。 这是我不明白的代码: static bool IntersectPixels(Rectangle rectangleA, Color[] dataA, Rectangle rectangleB, Color[] dataB) { // Find the bounds of the rectangle intersection int top = Math.Max(rectangleA.Top, rectangleB.Top); int bottom = Math.Min(rectangleA.Bottom, rectangleB.Bottom); int left = Math.Max(rectangleA.Left, rectangleB.Left); int right = Math.Min(rectangleA.Right, rectangleB.Right); // Check every point within the intersection bounds for (int y = top; y […]

除以两个数字总是等于零?

在我的Xna游戏中,我试图让我的playfield缩放到它正在运行的屏幕上。 为此,我使用比例来查找真实窗口相对于我的playfield缩放的百分比。 为此,我将实际宽度除以虚拟宽度: float _percent = _realViewport.Width / this._viewport.Width; 不过,我总是在_percent变量中得到0。 我在代码中的那一行设置了一个调试停止点,并分析了变量。 this._viewport.Width等于640,而_realViewport.Width等于1280.所以,使用我的计算器,640/1280应该等于0.5,但在我的代码中我总是得到0,而不是0.5。 它为什么这样做?

在XNA中与3D四边形相交?

所以我成功制作了一个代表鼠标未被投射到世界的光线,现在我需要检查光线是否可以与四边形物体相交,这是我用来获取光线的代码: public Ray GetMouseRay() { Vector2 mousePosition = new Vector2(cursor.getX(), cursor.getY()); Vector3 nearPoint = new Vector3(mousePosition, 0); Vector3 farPoint = new Vector3(mousePosition, 1); nearPoint = viewport.Unproject(nearPoint, projectionMatrix, viewMatrix, Matrix.Identity); farPoint = viewport.Unproject(farPoint, projectionMatrix, viewMatrix, Matrix.Identity); Vector3 direction = farPoint – nearPoint; direction.Normalize(); return new Ray(nearPoint, direction); } 同样,这是我的四元结构,我用它在3d空间中绘制一个“立方体世界”。 public struct Quad {public Vector3 Origin; public […]

Windows Phone 7中的媒体播放器

我正在使用Windows Phone 7中的媒体播放器播放手机歌曲集中的音乐。 但是当它播放音乐时,它们将是一个例外而且错误正在陈述 尚未调用FrameworkDispatcher.Update。 定期的FrameworkDispatcher.Update调用是必要的,以便消除和忘记声音效果和框架事件才能正常运行。 我该如何修改我的代码? private void songBtn_Click(object sender, RoutedEventArgs e) { using (var ml = new MediaLibrary()) { foreach (var song in ml.Songs) { System.Diagnostics.Debug.WriteLine(song.Artist + ” ” + song.Name); MessageBox.Show(song.Artist + ” ” + song.Name); } MediaPlayer.Play(ml.Songs[0]); } }

XNA旋转纹理2D

我想在XNA中旋转纹理。 我知道我可以在绘制时旋转它,但我希望Texture2D变量是旋转纹理。 有没有办法做到这一点?

使用out / ref与return相比有什么好处?

我正在使用XNA框架制作一个游戏,所以我使用很多在向量上运行的函数。 (特别是Vector2 (64位结构))。 困扰我的是大多数方法都是用ref和out参数定义的。 这是一个例子: void Min(ref Vector2 value1, ref Vector2 value2, out Vector2 result) 我也觉得有点奇怪。 还有另一个明显更明显 public static Vector2 Min(Vector2 value1, Vector2 value2); 基本上,几乎所有的函数都有ref和s的重载。 类似的,其他API 。 这个设计有什么好处? XNA针对性能进行了优化,可能是结果吗? 说,Quaternion需要128b,其中ref更少。 编辑: 这是一个测试代码: public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; private Vector2 vec1 = new Vector2(1, 2); private Vector2 vec2 = new Vector2(2, […]

写入RenderTarget后,如何有效地克隆输出?

XNA noob在这里,每天都在学习。 我刚刚研究了如何使用RenderTarget2D将多个纹理合成为一个。 然而,虽然我可以将RenderTarget2D用作Texture2D用于大多数目的,但是存在一个重要的区别:当后缓冲区resize时这些渲染的纹理会丢失(毫无疑问,在其他情况下,如图形设备内存不足)。 目前,我只是将完成的RenderTarget2D复制到一个新的非易失性Texture2D对象中。 不过,我这样做的代码非常难看。 有没有更优雅的方式来做到这一点? 也许我只是累了,但我无法在Google或SO上找到答案。 略有简化: public static Texture2D MergeTextures(int width, int height, IEnumerable<Tuple> textures) { RenderTarget2D buffer = new RenderTarget2D(_device, width, height); _device.SetRenderTarget(buffer); _device.Clear(Color.Transparent); SpriteBatch spriteBatch = new SpriteBatch(_device); spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied); // Paint each texture over the one before, in the appropriate color Rectangle rectangle = new Rectangle(0, 0, width, height); […]

XNA鼠标移动

我之前在XNA做了几场比赛,我即将开始一个新项目。 我想做的一件事就是让鼠标移动。 只是为了澄清(因为我看到一些类似的问题导致混乱)我想得到鼠标的运动。 不是光标的位置或从一帧到下一帧的位置变化。 我只想了解鼠标移动方式的数据。 在我之前的游戏中,我只需将(隐藏)光标重置到视口中间并查看位置的变化。 然而,这似乎有点作弊,并导致我的代码中的一些混乱的计算。 那么有没有办法让鼠标移动返回程序? 谢谢,马特 编辑: 回应第一条评论。 在这种情况下,我所指的光标位置是鼠标指针的屏幕位置。 我所指的鼠标的移动是在物理上移动鼠标。 XNA似乎有一个单词mouse与指针(或光标)同义。 我遇到的问题是,尽管鼠标向左移动,但由于光标位于屏幕边缘,我无法在程序中获得该移动。

MonoGame中的ContentLoadException

我一直在尝试使用Xamarin Studio在MonoGame中加载纹理。 我的代码设置如下: #region Using Statements using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Storage; using Microsoft.Xna.Framework.Input; #endregion namespace TestGame { /// /// This is the main type for your game /// public class Game1 : Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; //Game World Texture2D texture; Vector2 position = new Vector2(0,0); public Game1 () { graphics […]

无法在DLL“opengl32.dll”中找到名为“glBindFramebuffer”的入口点。 在MonoGame 3.0中

最近我在笔记本电脑上安装了MonoGame 3.0。 我从项目模板中选了一个乐队New“MonoGame Windows OpenGL Project”并尝试运行它,我得到了这个例外。 Unable to find an entry point named ‘glBindFramebuffer’ in DLL ‘opengl32.dll’. 例外是: public Game1() : base() { graphics = new GraphicsDeviceManager(this);<—-|Unable to find an entry point named 'glBindFramebuffer' in DLL 'opengl32.dll' 我安装了: MonoDevelop 3.0.6 gtk-sharp-2.12.10.win32 Opentk-2010-10-06 XNAGS40_Setup jdk-7u9-windows-x64 MonoGame3.0 我在用 : Windows 7 x64 Visual studio 2012 ASUS A52F […]