Tag Info

New answers tagged

3

You can do this in two ways, both of which require 3D cameras and projection: First, give all of your objects a 3D position in the world. // XYZ Vector3 Position; Next, create a camera with a position and orientation: class Camera { // Position of the camera in the world Vector3 Position; // Place where the camera is looking Vector3 ...


0

Assuming "LoadContent" gets called once at startup and "Update" gets called every frame, your issue is probably because the ball's X and Y coordinate got set to 5 every frame in the update method, therefore, it wouldn't be moving around freely... If it gets called once in the LoadContent method then it does not continually update the X and Y position to be ...


0

I have found the solution to this somewhere else. Adding a bigger if statement such as this : private int elapsedTime = 0; //Declared at class level public override void Update(GameTime gameTime) { elapsedTime += gameTime.ElapsedGameTime.TotalMilliseconds; if (elapsedTime > 500) { elapsedTime = 0; birdbox3.X += 5; birdbox3.Y -= 5; ...


0

This isn't really so much of a MonoGame issue as much as it is a .NET issue. The XML files are unimportant and can safely be deleted as they only contain the documentation for the matching DLL files. I'm not sure if there is any kind of legal requirement for you to keep them around but I seriously doubt it. I am not a lawyer. Moving the DLL files though ...


0

In my game, I do this by setting UVS in vertex data and drawing a mesh for the map using texture coords from the vertex data. Basically: Create a tile map that is the same aspect ratio as the sprite sheet you are using to draw your current tile map; where each pixel represents a tile. Pass this to the shader. Create a vertex buffer that is just a mesh ...


1

So long as the SpriteSortMode is SpriteSortMode.Immediate you can make alterations to graphics device in between draw calls which allows you to change the ScissorRectangle, RasterizerState, SamplerStates, ect... Of course you lose the performance optimization from the batching; however, it is sometimes worth it if the alternative is creating many begin/end ...


0

Other than being more performance efficient, I find it simply easier. It requires a little extra work to make sure your images are always within their bounds when creating the art, but it's a lot easier being able to see all the images you're dealing with at the moment. It's also easier to code, in my opinion. I simply have an array of objects like: sheet ...


0

To get continuous updates without degrading the UI performance, you'll need the following trick to hook into the windows message queue: public static class NativeMethods { [StructLayout(LayoutKind.Sequential)] public struct Message { public IntPtr hWnd; public UInt32 msg; public IntPtr wParam; public IntPtr ...


1

You are right that the correct function is Unproject. Try this: Vector3 modelPosition = graphics.GraphicsDevice.Viewport.Unproject( new Vector3(100.0f, 100.0f, 0.01f), // Note the 0.01f! effect.Projection, effect.View, Matrix.Identity); The 0.01f means you want a point that is 1% of the way between your near and far clip planes (the ...


2

This question seems to be an X/Y problem. I think what you are really asking "how do I rotate a set of triangles?" You've settled on a very slow, very wrong solution to this problem. You should never be directly modifying vertex data on the CPU, unless you absolutely have to. I think your answer boils down to replacing: ...


0

Like above suggestion made... "Note that if your color change affects every vertex with one unique color, you may consider to pass to a shader a single color as a parameter, and do not modify vertex." ...if you do need to pass more than one color, I would suggest adding a texture parameter and then assigning the color in the effect file using something ...


2

EDIT: I see your updates now, I'd suggest you try implementing something such as my first suggestion. Since you didn't post any of your code, I'm going to have to guess at how you're doing the collisions. Are you using a single pixel collision check between the player and the enemy with the wall or other related sprites around it? If so, there are probably ...


0

In the similar scenario i've used polling model (updating input every frame), composite pattern (which you already implemented) and rectangle hit detection. Every frame visual tree root (GUIManager, in my case) polls its children, calling the Update with the mouse coordinates, until one of them reports that the mouse is inside of it. This control will also ...


2

To check your collision you simply take the players position and divide it with the size of each map element to get the index of where the player is in the map, then check for collision surrounding that. The player is 48x32 and the map is 16x16 so (48,32) / (16,16) = (3,2). But since the player can move smoothly you need to add one more coordinate to each ...


0

This function takes in mouse coordinates and picks the model from the 3d scene by shooting a ray through it. Btw the screen size in world coordinates is 2x2 stretching from -1 to +1 on both the x and y axis. The screen size in pixels would be mClientWidth and mClientHeight. You'll see both those in "Compute picking ray in view space" void Pick(int sx, int ...


0

In class Player you are wrongly creating a new Game1 theGame1 = new Game1(); instance. That means you are trying to run 2 games at once. This is not what you are trying to do. Your Game should only have 1 instance and that is in your Program.cs file in the main method which starts running your game: static void Main(string[] args) { using (Game1 game = ...


1

It looks like hardware instancing isn't supported by MonoGame yet, which is ideal. That leaves us with the answer to MonoGame: Draw thousands of quads without hardware instancing. Still, I've included an explanation of how it would be done if they get around to it. Hardware Instancing (pure XNA HiDef only for now) It's been a while since I've done this, so ...


-1

I would recomend you to not use this technique, but instead use layers. In my opinion, layers are the best alternative (of those which I know). Then you would just add each sprite to one of your layers and just loop through each of them with a simple loop, and render the content of each of them. If that rendering technique doesn't suit you, then you could ...


0

Here's another trick that can be helpful: If you plan to set up a large group of these, you can first test a rectangle that encompasses the component rectangles, then test the interior rectangles individually. For P[1] we check whether it intersects R[ab]. Since it doesn't we don't have to check R[a] or R[b]. P[2] intersects R[ab], so we have to check ...


0

Unfortunately, there is not. By definition, a rectangle has four points, and the new figure has six. This is something to do with the library, however you could most likely create a wrapper around a few rectangles that has a similar API to the XNA rectangle class. This, I think, is the only way to accomplish something like this excepting @SteveH's ...


0

The closest you can do something like this: If(not in red rectangle) return;//no collision else if(not in blue rectangle) //run collision code


2

Sort them based on their Y position and draw them. You are over-thinking it. Only worry about the performance if you implement it, it appears slow and you discover (via scientific profiling) that the sorting is the bottleneck. Fifty or sixty objects is pretty trivial, all things considered. It's very possible you could achieve reasonable performance using a ...


0

Finally fixed by naming the parent joint of any model I have by the model's name then I get to read from the file I need by getting the name of the first bone in my mesh and excluding the extra '1' in the end of the string. Now each model will know which file to load for the animations without any fuzz.


1

You load the texture perfectly, but I don't see any code regarding the drawing of it. Add this: spriteBatch.Draw(image, new Vector(0f, 0f), Color.White); into your SplashScreen's Draw function.


0

Okay i fix the shake but i need to use ints and dont shake for pixel per pixel movement The solution of this was hereMatrix.CreateTranslation((int)-_pos.X,(int)-_pos.Y, 0)* and change by this Matrix.CreateTranslation(-_pos.X,-_pos.Y, 0)*


0

Try this (assuming _pos is Vector): return new Rectangle((int)(_pos.X / global.zoom), (int)(_pos.Y / global.zoom), 320, 240); Because: (int)0.5f / 1 == 0 / 1 == 0 1 / 2 == 0 (float)1 / 2 == 0.5f


0

Ok I was able to fix the issue on my own! I figured out that all color values become less as the mask blurs. So where the mask was fading out, not only were the A values fading, but the R G and B values were fading too! I'm not sure why that is, but here is the change that fixed it: sampler s0; texture textu; sampler tex_sampler = sampler_state{Texture = ...


1

Re-psuedo-coded: //draw pillar LightMapTexture.Clear(0,0,0,0); //Transparent everywhere spriteBatch.Begin(Immediate, Alpha); spriteBatch.Draw(Texture, new Rectangle(PillarX, PillarY, Width, Height), Color.White); //Still transparent everywhere except texture; texture may be partially transparent also customBlendState = new BlendState(); ...


0

No. BasicEffect cannot be told how to calculate the light-space coordinates, nor how to compare the depths. It is a "basic" Phong shader. Implementing this is fairly straight-forward: -Draw the scene from the light's perspective into a texture, recording the scene depth only. -Draw the scene again from the camera's perspective into a different texture using ...


0

Simply use the SpriteBatch.Draw overload which allows you to specify the destination rectangle: public override void Draw(Microsoft.Xna.Framework.GameTime gameTime) { spriteBatch.Begin(SpriteSortMode.Deferred); spriteBatch.Draw( texture: texture, destinationRectangle: destinationRectangle, sourceRectangle: null, ...


0

Depending on what you meant, try this: Method 1: (if you are indeed working in 2D) -Drawn from any angle, a BoundingSphere is a circle -A BoundingBox with "0" height is a rectangle -After constructing the two, use the .intersects method. Method 2: (un-confirmed/tested) -Bright red circles are circle(s) to be tested against the rectangle. -Blue arrows ...


1

As with anything in programming, there's multiple ways to do this. I'm not sure if what I would do is the best/fastest way, but it's a way to get the job done: First, I would check if the circle and the rectangle are remotely close to eachother by checking if (vector2.distancesquared(circle.centerpoint,new vector2(rectangle.x,rectangle.y)) <= ...


0

Simply drawing the texture to a smaller quad will scale it down automatically for you; there's no rule stating that the dimensions of the quad you draw a texture to have to be the same as the dimensions of the texture. In your specific case, you can take a 2100x1480 texture and draw a 164x115 quad using it, and the MinFilter you specify in your sampler ...


0

I ended up doing something that might seem stupid and costly that I loop at all the files till I find the right one and ignoring the exception that I get if the animations doesn't match the model. foreach (string file in Directory.EnumerateFiles(@"F:\Education\Animations", "*.txt")) { try { animationClips = ...


1

First of all your hardware has to support MultiSampling. You can check this with the below property. GraphicsAdapter.CheckDeviceMultiSampleType In addition to enabling it for the back buffer graphics.PreferMultiSampling = true; You can create a new RasterizerState that has the field MultiSampleAntiAlias set to true and pas this into SpriteBatch.Begin. ...



Top 50 recent answers are included