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

I don't think you should try converting the entire map into a single height map, exactly because of the problem you described. Maps can have arbitrary complexity which you wouldn't be able to represent in a height map. But you don't need to have a fixed slope for each type of tile either. You could store collision information on a per pixel basis for each ...


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

Here's the problems you are having: Sorting for sprite batches only applies within that batch. At End, everything in the batch gets drawn to screen and becomes pixels. The default depth state for SpriteBatch does not read the depth buffer. State objects (eg: SamplerState) are read-only once they are used. In this case, you're accessing the state that the ...


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

Depth testing, according to the description of modern 3D pipelines, is done after the pixel shader, which is why Direct3D provides the DEPTH output semantic and OpenGL provides the gl_FragDepth built-in variable that allow you to change the value against which depth testing is performed. However, it's kind of a waste of precious GPU processing power to ...


8

Although this is already answered, allow me to offer another equation: y = mx + b, where y is the coordinate calculated, m is the slope (-1 for down at 45 degrees, 1 for up at 45 degrees), and b is the y-intercept -- the y-coordinate where x=0. This allows you slightly more flexibility; you can change m to calculate a different slope other than 45-degrees. ...


8

Instead of using TotalGameTime use ElapsedGameTime and accumulate the running total yourself in some variable. Then when you pause the game all you have to do is to stop adding the elapsed time to the variable. Here's an example: float spawnTimer = 0.0f; float timeBetweenSpawns = 1.5f; private void Update(GameTime gameTime) { // Perform actions that ...


8

If a character can only perform one action at a time, then you can use the State pattern to represent that action. Basically this means that your character contains an object which handles the current state of the character, or specifically in this case, the current action. Typically you derive all your states from a standard base class or interface, which ...


8

From my personal experience with XNA, it's a pain. I think the way they expect us to do it, is to write our own GUI controls from the ground up. Buttons and checkboxes aren't so bad, but when you want lists, or text fields, it can eat up a lot of your development time. I would highly recommend using a 3rd party GUI library. @ClassicThunder has developed one ...


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

First of all, to test this answer on Windows, use a fresh copy of the game and add the following line to the constructor of PlatformerGame. Window.AllowUserResizing = true; This will let you resize the window and see the changes in action. The easiest way is to simply scale the game so that it fits on screen. You need to pass a scaling matrix to ...


7

Let's say, for the sake of argument, that every frame takes the same amount of time: Δt. So if you say that t milliseconds have elapsed since you started your game, you could also say that (n · Δt) milliseconds have passed (n frames that each took Δt milliseconds). You're applying the change to the translation variable every frame, which you can ...


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.


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