Advertisement Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

556 Good

About stein102

  • Rank

Personal Information

  • Interests

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Added you on discord. I may be interested in a java dev position.
  2. I'm trying to render a player texture on top of a TiledMap in LibGDX, my issue is that the map renders correctly, but the player texture is way larger than it should be. I'm sure it has something to do with my lack of understanding of the camera/viewport system, but I can't quite figure it out. game.unitsPerTile = 32 in this case. The texture in question is 32x64. public class GameScreen implements Screen { final Engine2D game; private OrthographicCamera camera; static final int GAME_WIDTH = 100; static final int GAME_HEIGHT = 100; private TiledMap map; private OrthogonalTiledMapRenderer mapRenderer; private Player player; public GameScreen(Engine2D game) { = game; float screenWidth =; float screenHeight =; float aspectRatio = screenHeight/screenWidth; camera = new OrthographicCamera(30,30*aspectRatio); map = new TmxMapLoader().load("Map1.tmx"); mapRenderer = new OrthogonalTiledMapRenderer(map,1/game.unitsPerTile); TiledMapTileMapObject startPoint = (TiledMapTileMapObject)map.getLayers().get("Objects").getObjects().get("startZone"); player = new Player(); player.setPositionX(startPoint.getX()/game.unitsPerTile); player.setPositionY(startPoint.getY()/game.unitsPerTile); } @Override public void render(float delta) {, 0, 0, 1);; game.batch.setProjectionMatrix(camera.combined); camera.position.x = player.getPositionX() + camera.viewportWidth/2; camera.position.y = player.getPositionY() + camera.viewportHeight/2; // tell the camera to update its matrices. camera.update(); mapRenderer.render(); mapRenderer.setView(camera); // begin a new batch and draw the bucket and // all drops game.batch.begin(); game.batch.draw(player.getTexture(),player.getPositionX(),player.getPositionY()); game.batch.end(); } }
  3. 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?
  4. stein102

    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; } }
  5. stein102

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

    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.
  7. 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?
  8. 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.
  9. 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; }
  10. 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); } } } }
  11. 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 -; 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"); } }
  12. When an event fires, you could place it in a queue and during the game loop, iterate through it and handle them accordingly.
  13. stein102

    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!
  14. stein102

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

    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?
  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!