Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

324 Neutral

About MatejaS

  • Rank
  1. Hi guys, I'm making a retro game in libGDX, and I've encountered a problem. I'm using FitViewport to add letterboxing and make the game look nice on all resolutions. Anyways, it's a shooter game and I need to draw an "aim" cursor on mouse position. Now, when there is no letterboxing (i.e. the aspect ratio is the same) it's all good, but otherwise, the cursor will not follow the mouse exactly and there will be an increasing gap (look at the image). I'm not sure if this is a bug or something.. Also, I should note that I use OrthographicCamera and not FBOs. Relevant code: camera = new OrthographicCamera(); viewport = new FitViewport(WIDTH, HEIGHT, camera); viewport.apply(); camera.position.set(camera.viewportWidth / 2,camera.viewportHeight / 2, 0); Mouse handling code: public class MMouse { private OrthographicCamera camera; private Vector3 pos; public MMouse(OrthographicCamera camera) { this.camera = camera; pos = new Vector3(); } public void update() { final int screenX = Gdx.input.getX(); final int screenY = Gdx.input.getY(); pos.set(screenX, screenY, 0); camera.unproject(pos); } public float getX() { return pos.x; } public float getY() { return pos.y; } } I've tried using event-driven input too, nothing changed.   PS: Sorry for bad photo, I had some problems taking a screenshot..   Have a nice day, MatejaS
  2. MatejaS

    LibGDX viewports

    Please? :)
  3. Hello,   Is there a way in LibGDX to make the (0, 0) point where the beginning of the red part of the window is (not counting pillarboxes) ? (Green circle in the image), and make it not able to render on top of pillarboxes (only render on the red part) ? I don't want to use Viewport-s.   Thanks in advance, MatejaS
  4. MatejaS

    Android game resolutions

    Thanks for the link L.Spiro!   Richard, now that I have thought about it, I think the formula for the screen height on your blog is incorrect. It says: ContentHeight = ContentWidth * (ScreenWidth / ScreenHeight), but shouldn't it be ContentHeight = ContentWidth * (ScreenHeight / ScreenWidth) ? Also, when I calculate the height, then what? I guess I should scale to fit the device, but as I said, I don't want to scale by something such as 2.25... Based on Spiro's link, I assume I should find a base (constant) width that is a denominator of all the screen sizes? That's pretty hard with all the resolutions..
  5. MatejaS

    Android game resolutions

    I was thinking about this topic and I realized that by using Richard's method (which is IMO the best), I'll need to scale the content to fit the device. That wouldn't be a problem if my games weren't pixel art. But they are, and scaling pixel art by a factor not a whole number, such as 2/3, is not good because it will look ugly... I've found some information on these sites: http://www.badlogicgames.com/forum/viewtopic.php?f=11&t=15293 https://www.allegro.cc/forums/thread/612318   Is this a problem? And if it is, is there a workaround?
  6. MatejaS

    Android game resolutions

    Thank you very much Olof and Richard!
  7. Hello guys, I'm making a retro pixel art game for Android using LibGDX. Now I'm in the middle of getting it to work on different resolutions. I've read about Viewport-s and I know there are lots of questions about this, but mine is a bit different. I'm not asking for an implementation, but for the way the "professionals" do it. Stretching is not an option because my graphics are pixel art and would look bad when stretched. So there are two things I can do: 1. letterboxing - it seems like the simplest thing to do, but do other games actually do this? Would the player not like to see letterboxes? 2. making the world larger - as my game is a horizontal scroller type of game, I can add more vertical content such as show more ground / sky, but I don't want players with bigger screens to be able to see more (to the right) than those with smaller screens.   And whatever I decide, I still need a base resolution, a "safe area"... What should it be?   Thanks for your replies, MatejaS
  8. MatejaS

    Another collision question

    Doesn't matter, solved it using pre-processing. Here's my new code, hopefully it'll help someone :) if (Gdx.input.isKeyPressed(Input.Keys.DOWN)) { offY = -1.0f; } if (Gdx.input.isKeyPressed(Input.Keys.UP)) { offY = 1.0f; } if (Gdx.input.isKeyPressed(Input.Keys.LEFT)) { offX = -1.0f; } if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)) { offX = 1.0f; } Rectangle np = new Rectangle(player.x, player.y + offY, 12, 11); if (np.overlaps(rect)) { if (offY > 0.0f) { offY -= np.y + player.height - rect.y; } else if (offY < 0.0f) { offY += rect.y + rect.height - np.y; } } np.setPosition(player.x + offX, player.y); if (np.overlaps(rect)) { if (offX > 0.0f) { offX -= np.x + player.width - rect.x; } else if (offX < 0.0f) { offX += rect.x + rect.width - np.x; } } player.x += offX; player.y += offY; (You can optimize this by not creating new Rectangle every frame)
  9. MatejaS

    Another collision question

    Can anyone help me please? I'm stuck.. I've been debugging it for the last two hours and still have no luck...
  10. Hello, I tried to make a top-down collision system, but it (again) didn't work... :( The problem is, when I'm colliding from the left / right and then press up / down, it will correct the Y position, and the player would jump to the top or the bottom of the colliding rectangle.When I change the code to be X first, then the same problem happens for Y collisions. Here's my code: if (Gdx.input.isKeyPressed(Input.Keys.DOWN)) { player.y--; dirY = 2; } else if (dirY == 2) { dirY = -1; } if (Gdx.input.isKeyPressed(Input.Keys.UP)) { player.y++; dirY = 3; } else if (dirY == 3) { dirY = -1; } if (Gdx.input.isKeyPressed(Input.Keys.LEFT)) { player.x--; dirX = 0; } else if (dirX == 0) { dirX = -1; } if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)) { player.x++; dirX = 1; } else if (dirX == 1) { dirX = -1; } if (player.overlaps(rect)) { switch (dirX) { case 0: // left player.x += ((rect.x + rect.width) - player.x); break; case 1: // right player.x -= (player.x + player.width - rect.x); break; } } if (player.overlaps(rect)) { switch (dirY) { case 2: // down player.y += rect.y + rect.height - player.y; break; case 3: // up player.y -= player.y + player.height - rect.y; break; } } (I use Java and LibGDX, but the code should be understandable) As you can see, collisions aren't my strongest skill. If anyone could help me, I would greatly appreciate it. MatejaS  
  11. I am making a game in LibGDX. I only want to target PC, so I didn't use gdx-setup, and added jars manually instead (I know it's generally a bad idea). Now I want to add Box2D to the project. What libraries do I need to add so it would work on all platforms (Windows, Mac, Linux). gdx-box2d.jar gdx-box2d-natives.jar Are these two all I need? There are other armeabi and x86 .so files...What are they for? Any help will be greatly appreciated. MatejaS
  12. MatejaS

    LibGDX wrong window size

    Thanks for your reply @MarkS :)
  13. MatejaS

    LibGDX wrong window size

    @Override public void create () { batch = new SpriteBatch(); img = new Texture("image.jpg"); cam = new OrthographicCamera(); cam.setToOrtho(false, 480, 800); viewport = new FitViewport(480, 800, cam); } @Override public void resize(int width, int height) { viewport.update(width, height, true); } @Override public void render () { Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.setProjectionMatrix(cam.combined); batch.begin(); batch.draw(img, 0, 0); batch.end(); } That's my game class. I've followed the tutorial on viewports..
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net 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!