Hot answers tagged

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

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


10

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

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

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

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


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

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

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


5

Not unless you are using features that the target platform does not support. If you want to use Effect files from a previous XNA project or an XNA sample, you'll need to process them with the MonoGame Effect processor to compile them for that specific platform. Some of these use OpenGL rather than DirectX as their graphics API, so the Effect file from XNA ...


5

Thermonology i call your "left/right rotation point of turret" joint "horizontal joint" and your "Up/down rotation point of barrel" joint "vertical joint". Calculate with Forward kinematic (transformations leading to (previously unknown) orientation/position) the Position and Upvector and Forwardvector (this vector points from the horizontal joint forward)....


5

Loose fitting, fast Generate a bounding AABB, which you likely already have (and is super cheap to compute for a sphere). Project the AABB's corners to the screen. Take the maximum and minimum X and Y values of the projected coordinates to form bounds of screen-space rectangle. This will be at least as large as the object. Depending on camera ...


5

Problem is two-fold: Determine how many pixels the model will take when rendered Replace model with a dot Suggestions: Pick the cut-off distance by eye. So when the model is this big and this far - it should be replaced with a dot. I would make it a property of the ship. Render all models that are closer than their cutoff distance as usual. Do not render ...


4

I see one huge mistake here not handled by any of the answers. Of course you should never draw and iterate over more tiles then you need too. What's less obviously is how you actually define the tiles. As i can see you made a tile class, i always used to do that too but it's a huge mistake. You probably have all sorts of functions in that class and that ...


4

You can use gameTime in the following manner along with 2 accumulator variables to store the time since the last shot and the number of shots taken since reload. gameTime.ElapsedGameTime.TotalSeconds represents the elapsed time since the last time the Update method was called (the time since last frame). If you accumulate each of these times (add them up ...


4

You just move the backgrounds despite them being meant to be static. For example, your character (and the camera) move 5 units to the right. Move the background right behind the character to the right by 1 unit. Move the background behind the other background by 2 units. Move the next background by 3 units, etc. The furthest away background (i.e. the ...


4

In order to project a vector v on u you can start by this equation, len(v) * len(u) * cos(theta) = v . u In order to the get the v component in the u direction. You can simply rearrange the equation by dividing on len(u), you get: len(v) * cos(theta) = (v . u)/len(u) Since len(v) * cos(theta) is the v component in the u direction and is a scalar. ...


4

Texture2D objects are allocated on system memory, but the actual textures loaded from image files are, on the other hand, loaded on the graphics card's memory. You are not completely off with your assumption, but here is how it goes when you want to load and render a simple texture: You load the texture into the graphics card's memory. You bind the texture ...


4

XNA things aren't in the prerequisites list for me either. Instead of that, go to the same location and click "Application Files", then make sure the Publish Status of the XNA libraries are set to "Prerequisite". To demonstrate, here's a screenshot of my settings for a new XNA project. (Click image for full size.)


4

Having the exactly same issue here - the following code snipped works perfectly fine: private void DoRenderSkybox (GameTime Time) { this.Device.SetRenderTarget(this.GridTexture); this.Device.SetRenderTarget(null); // compute a temporary transformation matrix containing // the combined world and projection transfromation Matrix WorldViewProjection ...


4

If you simply want to scale a sprite you can do spriteBatch.Begin(); spriteBatch.Draw(texture, position, null, Color.White, 0f, Vector2.Zero, 0.5f, SpriteEffects.None, 0f); spriteBatch.End(); or spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, null, null, Matrix.CreateScale(0.5f)); spriteBatch.Draw(texture, position, Color.White); ...


4

What your algorithm doesn't account for is if the ball's vertical speed is less than your paddle's speed (in your specific scenario, 3). Consider the following example: The ball is moving perfectly horizontally (y speed is zero) The AI paddle uses a vertical speed of 3 units as in your exact scenario The paddle's y position is 10 The ball's y position is ...


4

It is probably due to your gameloop is faster then your pressing speed. You should stop detecting space key when you pressed it once. For checking purpose you can use a flag for now. Like, bool _isKeyPressed = false; if (currentGameState == GameState.TitleScreen && !_isKeyPressed) { if (keyboard.IsKeyDown(Keys.Space)) { ...


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