stein102

Member
  • Content count

    231
  • Joined

  • Last visited

Community Reputation

556 Good

About stein102

  • Rank
    Member

Personal Information

  • Interests
    Programming
  1. I'm working on a voxel engine using Libgdx and I've been reading that using vertex buffering will increase my performance dramatically. I understand it to be packaging up all of the renderables into one object and sending that to the GPU as opposed to making thousands of draw calls individually. This sound really convenient, but I can't seem to wrap my head around it. I've looked at the wiki but still don't really know how this would be implemented. Edit: From further reading, what I think I want to do is convert a list of modelInstances into a mesh? Is that correct? If so, how do I go about doing that?
  2. Monogame make player follow mouse

    So I did what Spidi suggested and transformed the screen space to the world space and that didn't work. It turns out that the code works exactly as intended only if I don't zoom my camera. Here's the camera code. Any idea why it only works when my zoom is equal to 1? public class Camera2D { public Vector2 Position { get; set; } public float Rotation { get; set; } public float Zoom { get; set; } public Vector2 Origin { get; set; } static int TILE_HEIGHT_HALF = 64; static int TILE_WIDTH_HALF = 128; private readonly Viewport _viewport; public Camera2D(Viewport viewport) { _viewport = viewport; Rotation = 0; Zoom = 1; Origin = new Vector2(viewport.Width / 2f, viewport.Height / 2f); Position = Vector2.Zero; } public Matrix GetViewMatrix() { return Matrix.CreateTranslation(new Vector3(-Position, 0.0f)) * Matrix.CreateTranslation(new Vector3(-Origin, 0.0f)) * Matrix.CreateRotationZ(Rotation) * Matrix.CreateScale(Zoom, Zoom, 1) * Matrix.CreateTranslation(new Vector3(Origin, 0.0f)); } public Vector2 cartToIso(Vector2 cart) { Vector2 temp = new Vector2(0,0); temp.X = (cart.X - cart.Y) * TILE_WIDTH_HALF; temp.Y = (cart.X + cart.Y)*TILE_HEIGHT_HALF; return temp; } public Vector2 IsoToCart(Vector2 iso) { iso += Position; Vector2 temp = new Vector2(0, 0); temp.X = ((iso.X / TILE_WIDTH_HALF) + (iso.Y/TILE_HEIGHT_HALF))/2; temp.Y = ((iso.Y/TILE_HEIGHT_HALF) - (iso.X/TILE_WIDTH_HALF)) / 2; temp.X -= 0.5f; temp.Y += 0.5f; return temp; } }
  3. Monogame make player follow mouse

      That makes a lot of sense, I forgot to transform the mouse coordinates to the world space coordinates. I'll try this when I get home from school tomorrow and see how that works out. I'm guessing that will solve my issues. I'll post the results tomorrow.     I never really thought about that before, I'll change that too and keep that in mind.     Sorry about that, the chunk I posted is just inside my main update method and gets called every game loop, not every time the mouse button is pressed. My mistake.
  4. Monogame make player follow mouse

    It's called whenever the left mouse button is pressed.   After testing it again it seems like the movement direction is the last direction the mouse moved and not towards the mouse.
  5. I'm trying to have my player follow the mouse when the mouse button is held down but I'm having some trouble figuring it out. The motion is seemingly random. if(Mouse.GetState().LeftButton == ButtonState.Pressed) { int speed = 5; Vector2 mouse = new Vector2(Mouse.GetState().X, Mouse.GetState().Y); Vector2 direction = mouse - player.GetPosition(); direction.Normalize(); player.SetPosition(Vector2.Add(player.GetPosition(),(direction*speed))); } Any ideas?
  6. I've been avoiding a* since I'm not really sure how to implement it. I planning on generating the road first and then the landscape around it, does it really matter what order I do this in?   I like the idea of using waypoints, I may attempt something like that. I was looking in to midpoint displacement algorithms which would make the road look more natural, the issue is that it still takes the shortest path.
  7. The final goal is to create a road system similar to the one in Diablo2. A random enterance and exit are plotted on the map, then a winding path connects the two nodes. I have implemented a system that selects two random places on the edge of a map, then connects them. My issue is that the path is rather boring. Are there any good ways to improve the path my road takes? This is what I currently use to create the path: private List<Vector2> generatePath(Vector2 p1, Vector2 p2) { List<Vector2> nodes = new List<Vector2>(); nodes.Add(p1); while (!p1.Equals(p2)) { float xDiff = p2.X - p1.X; float yDiff = p2.Y - p1.Y; double atan = Math.Atan2(yDiff, xDiff); double quadrant = Math.Round(4 * atan / (2 * Math.PI) + 4) % 4; if (quadrant == 0) p1.X++; if (quadrant == 1) p1.Y++; if (quadrant == 2) p1.X--; if (quadrant == 3) p1.Y--; nodes.Add(p1); } nodes.Add(p2); return nodes; }
  8. I'm getting an error in my game where my foreground is not rendering on top of my background. My idea is that maybe I messed up my layer sorting method. Does anything look wrong with this? public static ArrayList<MapLayer> sortLayers(ArrayList<MapLayer> layers){ ArrayList<MapLayer> sortedLayers; sortedLayers = layers; int n = sortedLayers.size(); MapLayer temp = null; for(int i = 0; i < n; i++){ for(int j = 1; j < (n-1); j++){ if(sortedLayers.get(j-1).getDepth() > sortedLayers.get(j).getDepth()){ temp = sortedLayers.get(j-1); sortedLayers.set(j-1,sortedLayers.get(j)); sortedLayers.set(j,temp); } } } }
  9. I've been working on a isometric tilemap engine. Everything has been working fine up until recently when I tried implementing a moving camera. The tile picking has been off if the camera is moved. I've tried offsetting by the camera's displacement and it's still not giving the desired results. If I only move the camera along the x-axis, the tile picking works as intended, if any y-axis movement is involved, it doesn't behave correctly. I'm not sure what's going on here. Any help would be appreciated.   This method is called when a place on the game world is clicked. There is no correction for the camera in this method at the moment, I took it out due to it not working correctly. It's simply the base method that worked before the moving camera was implemented. The first two lines of code give me the camera's displacement along a given axis. cam.viewportWidth/2 is the default camera x coordinate. This is also applied to the Y-Axis.   If you need any more information, let me know and I can supply it. public void getTileAt(OrthographicCamera cam, Vector2 mouse){ camOffsetX = cam.viewportWidth/2-cam.position.x; camOffsetY = -(cam.viewportHeight/2-cam.position.y); System.out.println(camOffsetX + ":" + camOffsetY); mouse.x -= X_OFFSET; mouse.y = Math.abs(mouse.y - Gdx.graphics.getHeight()); Vector2 mp = isoToCart(mouse); Vector2 coords = new Vector2((float)Math.floor(mp.x), (float)Math.floor(mp.y)); try{ Tile t = new Tile("cube","redcube.png"); layers.get(0).setTileAt(t, (int)coords.x, (int)coords.y); System.out.println(coords); }catch(ArrayIndexOutOfBoundsException e){ System.out.println("Coords out of bounds"); } }
  10. When an event fires, you could place it in a queue and during the game loop, iterate through it and handle them accordingly.
  11. Platformer movement and collision

      AX and AY are the just properties for aX and aY, they basically act as getters and setters for the variables. aX and aY are being set in the main game loop where it just takes the direction of the thumbstick and adds to the variable depending on how much it's pressed.   1. I agree with you, I'll change that after I get it working correctly. This is just a prototype I was throwing together because I've never worked in monogame or C# before(I come from a Java and LibGDX background) 2. That was originally what I had done, but I changed it to what I have now because I was getting some stuttering when the block was on the ground. It would accelerate too quickly into the ground and a collision would occur to move the object back above the ground.  3. That makes a lot of sense, I'll give that one a shot.       Oh okay, I see what you mean. That had never occurred to me, I'll try implementing changing the velocity directly as opposed to the acceleration.   I'll look into adding an animation for the play and see what happens. I've never done anything like that with monogame so that means there's some more reading to be done :)   Thanks for all the advice!
  12. Platformer movement and collision

    Okay, I got a video up. Here's the link. The video is a bit long but it gets the point across.   It's kind of hard to tell from just the video but the change in direction seems to have a pretty large delay.
  13. Platformer movement and collision

      I found that in a thread a while ago(I don't remember where exactly) where it was suggested to check which collision axis was shallower to determine which collision has happened first. I have changed that already but I did so before seeing your post.   What I've done is get two time variables that are basically float timeY = intersection.Height/velocityY and the same for X. This has been a lot more accurate.   My problem I'm having now is that the movement feels VERY unnatural. But I suppose that is just a matter of tweaking values, right? I was also considering changing all my movement related variables from ints to floats to get slightly more smooth movements. Would this help?
  14. Platformer movement and collision

    I'm not at my PC at the moment but all the code for jumping does is increase the y velocity by a set amount. I can post a video of the behavior in the morning since I'm a little unsure how to explain it
  15. I'm working on getting a platformer prototype up and running in C# using monogame. The movement and collision "work" but are very awkward. For example, if you stand on the edge of a platform and jump straight up, you fall right through the platform. I'll post my code and hopefully someone sees something that doesn't look right. If any additional information is needed I can add more. public Player(GraphicsDevice device) { x = 100; y = 100; width = 32; height = 64; maxVX = 10; gravity = -2; grounded = false; Rect = new Rectangle(x, y, width, height); WhiteRectangle = new Texture2D(device, 1, 1); WhiteRectangle.SetData(new[] { Color.White }); } public void Update() { rect = new Rectangle(x, y, width, height); if (!grounded || standingOn==null) { aY = gravity; }else { aY = 0; } VY += AY; VX += AX; if (aX > 10) aX = 10; if (aX < -10) aX = -10; if (vX > maxVX) vX = maxVX; if (vX < -maxVX) vX = -maxVX; System.Console.WriteLine(vX +":" + aX); lastX = x; lastY = y; x += VX; y -= VY; } public void CollisionCheck(List<Platform> collideables) { foreach(var p in collideables) { if (rect.Intersects(p.Rect)) { Rectangle intersection = Rectangle.Intersect(rect, p.Rect); if(intersection.Height < intersection.Width) { if (y < p.Y) { standingOn = p; grounded = true; y = p.Y - height; vY = 0; aY = 0; }else { y = p.Y + p.Height + 1; vY = 0; } }else { if(x < p.X) { x = p.X - width - 1; }else { x = p.X + p.Width + 1; } } vX = 0; aX = 0; } } //Check if player falls off platform if (standingOn != null) { if(x+width < standingOn.X || x > standingOn.X +standingOn.Width) { grounded = false; standingOn = null; } } } public void ApplyFriction() { aX = 0; if (vX > 0) aX -= 2; if (vX < 0) aX += 2; } EDIT: Almost forgot to include the code that changes the acceleration player.AX += (int)(pad.ThumbSticks.Left.X * 10) / 5;