Hot answers tagged

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

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

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

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

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

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

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

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


3

No code from me, since I'm not that experienced with XNA, but this is more a general "issue": First of all - as mentioned in the comments - do not (never ever!) add fake loading screens! People will think it's really that ressource heavy which can show your app in a worse light than it actually should be. Especially on mobile you don't usually trust an app ...


3

You could define a set of textures (grass, dirt, rock) and use those. Let's say using these three layers (rock at the bottom, dirt on top and grass topmost), you can define three alpha channels to define how much of each texture is visible. Start with a simple noise map for your alpha channels and maybe take the slope of terrain into account. The more slope, ...


3

The official answer from Shawn Hargreaves (one of the developers of XNA) is The XNA Model class doesn't do any optimization at runtime: that all happens at build time inside the ModelProcessor. This is exactly why it is impossible to create a Model instance at runtime: the Model class depends on the processor to have optimized its data ready for ...


3

Most of the methods I've encountered have already been stated above -- but there's still one more that hasn't been mentioned. When the player encounters a vertical obstacle that's short enough (say, 1/3 their hight), simply put them on the top. Minecraft and the Source engine for example take this approach in that kind of situation. Additionally, this method ...


3

As Andon M. Coleman pointed out: The problem was that I treated the Depth Map as float4 and tried to get the r channel to retrieve my depth value. I now simply get a float value from the map and (for presentation purposes) multiply it with a scalar of 500, creating a new Texture with its r,g,b channel holding the data calculated before. Thanks!


3

First off, you'll likely have an easier time using vectors for this instead of a float value with rotation separately. (The name velocity implies speed and direction, you appear to only be storing a speed and keeping your direction in your r value). Next thing you'll want to acceleration. This will be the change in velocity over time. This is where you'll ...


3

It's likely the hitboxes are never colliding. It's not clear how you're creating the player hitbox, but if it's the same way, they'll never collide. You're creating a rectangle based off the position your object starts at. You should create a hitbox on the fly, based on the current position of the object at the time of the collision check. This ensures your ...


3

Game assets like sounds are usually best managed if preloaded in advance. You don't want the user to experience a delay in the sound effects every time a sound has to be loaded. You should implement a ResourceCache helper that manages game resources for you. Then things like sounds could be preloaded at each level start and unloaded when the level ends. ...


3

Just build the XNB file on your personal machine, and use that file in your project. Remove the .spritefont file from your content project. Then add the built XNB file to your game project, in an appropriate directory (generally "Content") and set its properties (select it and press F4) to "Copy if newer". This is off the top of my head. So look at the ...


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