Tag Info

New answers tagged

0

Ok it's actually really simple to achieve. First of all as u mentioned, ur engine direction describes the path of movement. This makes it comfortable to work with. First of all, always store a vector of the direction ur moving. Next u must have a vector of the lookat of ur engine. So for now when u start moving, let's say right, the both the direction ...


0

for (int x = 0; x < Tilemap.MAP_WIDTH; x++) { for (int y = 0; y < Tilemap.MAP_HEIGHT; y++) { if (tm.tile[x, y].bounds.Intersects(playerBounds)) { if (tm.tile[x, y].getSolid()) { foundCols++; } else ...


0

It is not just a rectangle/rectangle test. It is also a dot product test to determine which side of the slope line the other object is on. For this you will need to initialize the 2 end points of your slope. This becomes a line segment and the corners of your slope's collision rect. So your slope and rect both share point A & B. The algorithm gos like ...


0

Try adding effect.Alpha = 1f; The alpha channel was probably premultiplied (check the texture properties in your content section).


0

Managed to fix this by using Viewports when drawing the Rectangles / Cameras GraphicsDevice.Viewport = new Viewport(_level); spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null, null, _camera.ViewMatrix); DrawLevelTiles(); spriteBatch.End(); GraphicsDevice.Viewport = ...


1

I think you might be overcomplicating things - why not just set the "origin" of the hook to new Vector2(0, hookTexture.Height / 2) If you simply draw it like this: spriteBatch.Draw(hookTexture, position, null, Color.White, rotation, new Vector2(0, hookTexture.Height / 2), 1.0f, SpriteEffects.None, 0.0f); That way the hook is drawn and rotated around ...


2

One way to do this, is to draw your text 2 times in a different color at specific offsets. For example: public static void DrawText(SpriteBatch spritebatch, SpriteFont font, string text, Color backColor, Color frontColor, float scale, Vector2 position) { Vector2 origin = Vector2.Zero; spriteBatch.DrawString(font, text, position + ...


2

Yes, you can do this with no expensive trig at all. Steps: Find the distance between the 2 circles. Find the combined radius between the 2 circles. Subtract the distance from the combined radius to get the depth of the penetration. Multiply the direction between the circles by the penetration depth. I.e.: Circle c1; Circle c2; float Distance = ...


1

Your code has some serious issues. First of all, in games, you generally don't want to be moving objects on the screen by a flat amount per frame, because then the frame rate can make you go faster or slower, which is not a good thing. The way you want to be moving your objects is with delta time, which is the elapsed time between this and the previous ...


0

To follow an object I would recommend using Lerp and setting the camera's position to to your player object. You can achieve this by doing something like: camera.Pos = Vector2.Lerp(camera.Pos, player.Position); This should follow your player in a smoothly.


0

If you are using XNA's normal 2D graphics routines (i.e. Spritebatch) to draw your scene, a 3D camera script will not be helpful. Instead, store your camera position and scale as Vector2s and update your drawing code in this manner: spriteBatch.Begin(); spriteBatch.Draw(gameObject.texture, (gameObject.location - cameraOffset) * cameraScale, null, ...


0

There is only 1 optimization you need to implement: Vector2 Min, Max; Min = poly.Vertices[0]; Max = poly.Vertices[0]; for (int i = 1; i < poly.Vertices.Length; i++) { Vector2 Vertex = poly.Vertices[i]; if (Vertex.x < Min.x) { Min.x = Vertex.x; } else if (Vertex.x > Max.x) { Max.x = Vertex.x; } if ...


1

Please, at all cost, avoid using vector2(or 3 or 4 for that matter).Distance(). If you can, use DistanceSquared() instead. To get the actual distance, XNA uses the pythagorean theorem, which ultimately means that it needs to use the square root function. This is a relatively slow function. So use this instead: for (int x = 0; x < map.GetLength(0); x++) ...


-1

if you haven't already gotten this figured out, a simple way to do it without complicated path-finding is to check the position of all of the enemies vs yours. If the enemies are below you position, move them up. If they are too far to the left, move them right. It's as simple as that. Example: foreach (Enemy enemy in enemies) if(enemy.x > player.x) ...


0

You are forgetting to dispose your game object. [STAThread] static void Main() { using (Game1 game = new Game1()) game.Run(); using (Game1 game = new Game1()) game.Run(); }


1

You might be able to side-step using rectangles altogether. For a top-down shooter you could use bounding circles instead of boxes. Checking collision between circles is much easier and faster than checking collision between non-axis-aligned bounding boxes (just check if the distance squared is less than the sum of the radii squared) and you don't need to ...


0

Rather than polling for events, where the only option for higher precision is to poll faster, you could try listening for the events directly. You can attach an event listener to the windows event queue like so: // Define a message filter which all messages will pass through private class Filter : IMessageFilter { public bool PreFilterMessage(ref ...


3

Assuming you have translated this from the original Java code it looks like you have been a bit careless in adding brackets in a few places. For example the original code has: double t0 = 0.6 - x0 * x0 - y0 * y0 - z0 * z0; while you have: Dim t0 As Double = (0.6 - ((x0 * x0) - ((y0 * y0) - (z0 * z0)))) which if you remove the brackets is actually: Dim ...


5

Step 1 - Don't check collisions in each key, test them at the end In your example, you are checking collisions for each key independantly. This will cause some trouble and code replication. In order to avoid that, I would suggest you use temporary variables that will stock the movement, increment it for each key and test collisions only once at the end: ...


0

Well, since you asked for "properly" I would recommend shader based AA, but it depends on specific project. Look for FXAA if you want cheap AA, or there is SMAA for XNA somewhere around (although not as effective as its common implementation due to XNA stencil limitations).


2

You can simply render the pieces of colored text individually, specifying any color you want for each piece. In order to get the positioning correct, you can use the SpriteFont.MeasureString() method. string[] stringPieces = { "Hel", "lo, ", "wor", "ld!" }; Color[] colors = { Color.Blue, Color.Green, Color.Yellow, Color.Red }; Vector2 startPosition = new ...


0

I think you should try the Vector2.Lerp() method. It basically interpolates two Vector2 values, and it's great for camera movement. What you've got is fine - but this might just be a bit better. To use it you could simply have the position and size of the camera rectangle as two Vector2s and lerp them. Here's an example. Vector2 CurrentPosition; Vector2 ...


-1

Looks like you want to implement stteringbehaviours. Take a look a chapter 3 of this book. I think it would make your game look more natural if you implement it this way.


0

I assume your rectangle exist out of a X,Y,Width and Height. First, Create 4 Vector2 for your rectangle: Vector2 v1 = new Vector2(x,y); Vector2 v2 = new Vector2(x+width,y); Vector2 v3 = new Vector2(x,y+height); Vector2 v4 = new Vector2(x+width,y+height); These points are the 4 corners of your rectangle. Next apply some simple transformation on the ...


1

The game layer probably shouldn't know about the HUD layer. The HUD layer should maybe listen to events from the game layer. Your example is a bit vague, so let's say there is a button above each enemy that should have the lifetime of the enemy. You could make a button system that checks that the corresponding enemy(a component of the button) is still ...


3

I think the Observer Pattern may fit here. Instead of sending a message to your button, let your button observe some component.


0

In Monogame, the source code of your game is the only thing that is identical for every platform. Of course you would have to change how you handle inputs for every platform (for example windows doesn't have touch) and how you calculate the screen size (mobile doesn't have multi-monitor setups). If you chose to use the #IF __ANDROID__ and #IF WINDOWS ...


0

Monogame game is cross-platform compatible, but not in the sense that you just magically click and it will work. In most cases, you are going to need to tweak individual builds, in order to get them to function properly in each environment. If you consider supporting iOS or Android, you are going to have to look into the xamarin dependencies as well, which ...



Top 50 recent answers are included