xna

How do I use random numbers in C#?

限于喜欢 提交于 2020-01-03 14:11:02
问题 I'm working on Pong in C# w/ XNA. I want to use a random number (within a range) to determine things such as whether or not the ball rebounds straight, or at an angle, and how fast the ball moves when it hits a paddle. I want to know how to implement it. 回答1: Use the Random class. For example: Random r = new Random(); int nextValue = r.Next(0, 100); // Returns a random number from 0-99 回答2: Unless you need cryptographically secure numbers, Random should be fine for you... but there are two

Unable to reference microsoft.xna.framework.media.phoneextensions.dll

心不动则不痛 提交于 2020-01-02 10:17:49
问题 I am trying to follow this answer to add some audio files to the windows phone emulator's media library. But I get the error The type or namespace name 'PhoneExtensions' does not exist in the namespace 'Microsoft.Xna.Framework.Media' (are you missing an assembly reference?)` I am unable to reference microsoft.xna.framework.media.phoneextensions.dll as it is not present at the location C:\Program Files\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0\Profile\WindowsPhone71 I installed

Unable to reference microsoft.xna.framework.media.phoneextensions.dll

房东的猫 提交于 2020-01-02 10:17:43
问题 I am trying to follow this answer to add some audio files to the windows phone emulator's media library. But I get the error The type or namespace name 'PhoneExtensions' does not exist in the namespace 'Microsoft.Xna.Framework.Media' (are you missing an assembly reference?)` I am unable to reference microsoft.xna.framework.media.phoneextensions.dll as it is not present at the location C:\Program Files\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0\Profile\WindowsPhone71 I installed

Should I use Pools for particles if i forced to re-init every particle every time i create them

一曲冷凌霜 提交于 2020-01-02 06:27:14
问题 I am creating a particle system in XNA4 and I've bumped into problem. My first particle system was a simple list of particles, whose instances are created when needed. But then I read about using pools. My second system consists of a pool, filled with particles, and an emitter/controller. My pool is pretty basic, this is the code: class Pool<T> where T: new () { public T[] pool; public int nextItem = 0; public Pool(int capacity) { pool = new T[capacity]; for (int i = 0; i < capacity; i++) {

Drawing Bezier curves in MonoGame (XNA) produces scratchy lines

≯℡__Kan透↙ 提交于 2020-01-02 05:18:35
问题 I recently got into using MonoGame, and I love the library. However, I seem to be having some issues with drawing bezier curves The result that my code produces looks something like this Look bad, no? The lines aren't smooth at all. Let me show you some of the code: //This is what I call to get all points between which to draw. public static List<Point> computeCurvePoints(int steps) { List<Point> curvePoints = new List<Point>(); for (float x = 0; x < 1; x += 1 / (float)steps) { curvePoints

Checking if a point is inside a rotated rectangle

我怕爱的太早我们不能终老 提交于 2020-01-02 05:18:30
问题 I know this question has been asked a few times before, and I have read various posts about this. However I am struggling to get this to work. bool isClicked() { Vector2 origLoc = Location; Matrix rotationMatrix = Matrix.CreateRotationZ(-Rotation); Location = new Vector2(0 -(Texture.Width/2), 0 - (Texture.Height/2)); Vector2 rotatedPoint = new Vector2(Game1.mouseState.X, Game1.mouseState.Y); rotatedPoint = Vector2.Transform(rotatedPoint, rotationMatrix); if (Game1.mouseState.LeftButton ==

How to store structs of different types without boxing

▼魔方 西西 提交于 2020-01-02 01:41:11
问题 I'm creating a messaging system for use in an XNA game. My Message types are structs because I want them to behave in a Value Type way. struct MyMessageType1 : IMessage {} struct MyMessageType2 : IMessage {} List<IMessage> messageQueue = new List<IMessage>(); I want to be able to store Messages of different types in my message queue, but I want to do so without any of them being boxed. If I have the structs implement an interface such as IMessage and I try to store them in a List, they get

XNA WorldMatrix and ViewMatrix

♀尐吖头ヾ 提交于 2020-01-01 14:35:44
问题 I have created a Camera class that allows me to move around a scene in first person. The camera has worked just fine until I decided to use it as a location to add something to the 3D world. What I am trying to do is add a cube to the world when I press a mouse button. I want to cube to eventually travel away from the camera, but for now I just want to create it right in front of it. Sometimes it works and sometimes it creates it to one side or the other. It all depends on how much I've

XNA: What is the point of Unload()?

别来无恙 提交于 2020-01-01 09:38:18
问题 XNA games have an Unload() method, where content is supposed to be unloaded. But what is the point of this? If all the content is being unloaded, then the game must be exiting, in which case everything would be garbage collected anyway, right? 回答1: As far as I understand it, it's not useful for any standard uses, since as you say the garbage collector deals with things for you. However, it's useful to have an event called when your game is exiting for many things. For example you could send a

What the best XNA blog? [closed]

▼魔方 西西 提交于 2020-01-01 05:22:11
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 8 years ago . I know good general programming blogs (like coding horror ;) ). But I want very good specific XNA blog. Suggestions? 回答1: Shawn