Hot answers tagged

20

Yes. It involves a small amount of messing with XNA's internals. I've got a demonstration of a fix in the second half of this video. Background: The reason this happens is because XNA suspends its game clock when Game's underlying Form is resized (or moved, the events are the same). This, in turn, is because it is driving its game loop from Application....


13

Is there any notable performance between Vector2s and Vector3s, for example when adding or multiplying them, or when calling Normalize, Transform, or Distance? Yes, you have one more coordinate so you will use more CPU cycles. But it is very unlikely that it will ever give you any trouble. XNA 4 is using SIMD extensions for vector math (EDIT: on Windows ...


12

There are three general approaches to dealing with stairs in video games: The "Mario" approach is that you must jump to get up stairs. The "Castlevania" approach is that moving up/down stairs is a different sort of movement; you must press 'up' on the controller, and a special "stair-climbing" animation is played to traverse the stairs. A variant of this ...


11

In XNA there is a SignedInGamer class with a SignedInGamer.PlayerIndex member that should tell you just that if you can get a hold of the SignedInGamer object. To do that, there is the Gamer.SignedInGamers static property which contains a collection of SignedInGamer objects based on the current state of the system. This is from the Microsoft.Xna.Framework....


11

If you're able to rotate the boundingboxes, I would've put a 45 degree rotated box at the player's feet and combine it with one non-rotated box to represent the rest of the body. That could make the player automatically slide over anything small enough. Though, that would probably cause some clipping with the player model and the stairs. Another idea is to ...


10

Just make a normal C# project and include the XNA binaries. This will gain you access to the XNA data types and framework methods. My game does this and it works flawlessly.


10

In C#, having an instance (non-static) method in a class does not copy the instructions for each object created from that class. Static or not, the data that represents the instructions only exist in one place. The member variables, or state, of each of the instantiated objects do get their own space in memory. When you write a non-static method on a ...


8

You need to use SpriteFont.MeasureString. Vector2 textSize = mySpriteFont.MeasureString("Hello World"); Vector2 center = textSize / 2; The x component of textSize represents the width of the measured string while the y component represents the height.


8

I would imagine a custom pixel Shader for the SpriteBatch would be the fastest method here. Using something like this: // WARNING! UNTESTED CODE FOLLOWS void SpriteVertexShader(inout float4 color : COLOR0, inout float2 texCoord : TEXCOORD0, inout float4 position : POSITION0) { if (color == float4(1, 1, 0, 1) color = ...


7

Don't use a class for MapCell. Classes are allocate on the heap. Every MapCell hence has overhead associate with memory management (bookkeeping of the allocations, padding, etc.). There's also the overhead of all the internal data that every object instance has like the "vtable" handle (which isn't much but it adds up) and you don't need the featurs those ...


7

You have to add new a new SpriteFont item to your content project. Inside the .spritefont file, there is FontName element. Replace the default value with Courier New. Take note of the asset name of the .spritefont file you added. Because that is the name you should reference inside your game. Assuming you named the asset as courier, you could load the font ...


7

If you don't care about rotation, you can simply set the origin of the sprite to its center and rotate it 180 degrees (Math.PI). This is the same as flipping horizontally and vertically. If you do care about rotation, and the sprite is flipped both ways, you can just add Math.PI to the angle and you should be done (eg. 45 degrees + 180 degrees rotation ...


7

There are a couple of options. Blur the image itself (in Photoshop, GIMP, whatever). Blur the image using a shader (probably not too hard) Blur the image manually. (Blurring is really averaging of nearby pixels.) I would personally favour reason #1, unless there's a very strong reason not to. If you need the original, unblurred image, then keep it ...


7

To do this requires a little bit of knowledge of trigonometry to work out exactly where to move the sprite. C#'s Math class and XNA's MathHelper class can help considerably, but you will still need to know how to apply them. Your entity would first need to have the following two fields. public Vector2 Position { get;set; } public float RotationAngle { get;...


7

The usual way to handle this is that every time a bullet is fired you set some variable to your cooldown time. Every frame you decrement that variable by the frame time. If you try to fire and that value is greater than 0, you just ignore the fire input event. If that feels bad, a next step is to queue up a "they want to fire" action if they try to ...


7

There are no conversions of XNA to the android platform without using either MonoGame or EXNA. You will need to rewrite your game including all the rendering logic in either C# using Xamarin.Android or a complete rewrite in Java.


7

I've changed the shader according to the article suggested by Seth Battin. Now it performs perspectively correct quad texturing. Phew, bacon delivered: For the future generations that may never happen. The input is in a form of the line vertexes A1/A2, B1/B2 that creates diagonals (rather then sequential vertexes): public static Vector3 ...


6

That's your problem, right here: map[x,y] = new MapCell((byte)random.Next(4)); Each of those calls generates a new object, even if that object is identical to a million others already in the game. What you can use to alleviate the problem is called the "Flyweight Pattern." In this case, your MapCell instances become immutable (similar to, for example, ...


6

This is a typical scenario. You must create a 3rd project and place your event class in it. Set the other 2 projects to depend on it so it builds first. Set a reference to the 3rd project in the other 2 projects.


6

As catflier mentionned, moving from a "high level" framework like XNA to a low level Direct3D11 API would require quite some work in order to achieve the same results. But there are now some options that you could also consider: Use new SharpDX.Toolkit, which is basically a XNA like API on top of Direct3D11 API, running on Windows Desktop, WinRT and WP8. ...


6

Building on the example by ClassicThunder. The class below is a more complete example for someone who is new to XNA/MonorGame. Basically, drop it into your project and you can load textures from disk into a List or Dictionary. You'll probably want to utilize the .NET zip library to compress/decompress your assets manually and reduce clutter. If you're on ....


6

This is probably because your up vector is exactly opposite to the eye vector in the second example. This makes the cross product, which is used to calculate the view matrix unreliable (for a lack of a better word). EDIT: If this is not enough information, then you should read up on how a view matrix is calculated. You need three things to do that, an eye ...


6

Yes. If you look at the definition of that enum you'll see it has [FlagsAttribute] which means you can combine the enum values with the | operator.


6

What you are probably looking for is a form of edge detection before, after, or even before and after your Gaussian blur. Maybe a version of Sobel Edge Detection could work. I know your game is 2D but if the wiki page is too rough here's a tutorial on how to get it working in the UDK that might translate over better. Your edge detection only really has to ...


6

Though your question about Draw arguments is understandable, I do think it is by design. Also, the Top/Left coordinates of the rectangle are not the Top/Left coordinates of the drawn sprite, but rather the coordinates of the Origin.X/Origin.Y texture pixel. This is an incorrect statement. Your origin has become the top-left visible pixel, which is ...


6

Quite the opposite. MonoGame stands to be the perfect replacement for existing XNA developers. It doesn't do everything that XNA did yet but there's no good reason why it can't. Coupled with the fact that it sports many more platforms and it's already being used in many reputable games I'm confident it will be great for some time to come. Edit: I wrote ...


6

You could just calculate the dot-product of your "up-vector" and the normal of the surface below your feet. So assume you have a world where positive-Y is up, then your up-vector is (0,1,0). Then get the normal of the triangle below your feet and calculate the dot-product. float dot = Vector3.Dot(upVector, normalVector); The dot product will be the cosine ...


6

It seems to me that you don't have any depth testing going on. For that you have to have a depth buffer and write to that while drawing your geometry. If you are drawing to a rendertarget then create it like this: RenderTarget2D rt = new RenderTarget2D(device, device.Viewport.Width, device.Viewport.Height, false, SurfaceFormat.Color, DepthFormat.Depth24); ...


5

Keep in mind I had this problem over 2 years ago and I have since moved onto Unity 3D. This is more of a conclusion than a solution. The main problem was that moving the bones did not move the mesh. I used Cinema 4D to model and rig the model and exported as fbx. There are many fbx export options in C4D and I tried many variants with no success. Here are ...


Only top voted, non community-wiki answers of a minimum length are eligible