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

a:Object; b:Object; dx:Number = a.x - b.x; //distance by x dy:Number = a.y - b.y; distance:Number = Math.sqrt ( dx*dx + dy*dy ); If you want to simulate magnet behavior, you want to base forces on distance between them. Physics say so: But you will be fine with: force = Math.floor ( MAX_FORCE / distance ); And then you need to use trigonometry to apply ...


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's two types of friction, static friction and kinetic friction. Static friction is the friction that needs to be overcome to get something moving from rest. You'll notice when pushing a box across the floor, it can often take more force to get it moving than to keep it moving. Or you'll be applying force and it will jolt forward and you'll have to not ...


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

As mentioned in the comments you can load a Texture from stream. The only issue with this is the content processor premultiplies the alpha which is necessary unless you use BlendState.NonPremultiplied as the BlendState argument when creating your SpriteBatch. Below is a snippet of code that I use to premultiplied the alpha for textures loaded via a stream. ...


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

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

keyboardState = Keyboard.GetState(); if (!oldKeyBoardState.IsKeyDown(Keys.F12) && keyboardState.IsKeyDown(Keys.F12)) { //Do Stuff } oldKeyBoardState = keyboardState; Using 2 keyboard states is the best way in my mind, and I would say you are correct. I wouldn't even use a class, I would just make a method and call it IsToggled(Keys.F12); ...


6

None-physical way (not spring physics): If I simply wanted an object to pull towards another object and stop there I would use this instead: Define too far apart as a radius r, any object farther than that radius will be attracted to its partner. R = r*r; Lets say the attractor is A and the other object is B Pick a small percentage representing your ...


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

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

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 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 ...


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