Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8305445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:07:03+00:00 2026-06-08T18:07:03+00:00

I just began playing with LibGDX, and am already facing a problem with the

  • 0

I just began playing with LibGDX, and am already facing a problem with the camera.

I saw some tutos on Internet which told, if I understood well, that in a 2D game using LibGDX you have to recalculate the position of all of your entities (I mean everyinthg on the screen) taking in parameter the velocity etc…

For me it means that the camera doesn’t move, but the world that it shows.
I would like to do opposite, moving the camera but not the world, as it makes more sense to me, and looks to be easier as I just have to move the camera, not all entities. So I don’t want the world to move and my camera to show changes, but my camera to move and show changes. So even if some entities doesn’t move (their coordinates x & y doesn’t change), it will look like as the camera moves.

So I have a Camera class that inherit from OrthographicalCamera, and an Entity class.
I have also 2 interfaces PositionListener & PositionListenable => Pattern Observer.

So what I tried to do is:
– My camera “listens” to only one of my Entity (e.g. the player)
– When my entity moves, it updates the camera with its coordinate (x, y) and my camera changes its position to x and y to follow my entity.

Here is the code in Camera.java :

public class Camera extends OrthographicCamera implements PositionListener {

    public Camera(float width, float height) {
        super(width, height);
    }

    @Override
    public void entityMoved(float newX, float newY) {
        translate(newX - position.x, newY - position.y);
        update();
        Gdx.app.log("entityMoved()", "newX=" + newX + " - newY=" + newY);
        Gdx.app.log("entityMoved()", "position.x=" + position.x + " - position.y=" + position.y);
}

}

When I read logs, I see that position.x and position.y changed as I expected to do to follow my entity, but visually the camera doesn’t move ?? Everything looks the same as if my camera doesn’t translate !

My camera is not moving at all, only my entity !
What am I missing ? I read something about “viewPort” but really didn’t get the thing as I am a beginner with LibGDX.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:07:04+00:00Added an answer on June 8, 2026 at 6:07 pm

    Ok here how I got it to work.
    Here is the entityMoved() method :

    @Override
    public void entityMoved(float newX, float newY) {
        translate(newX - position.x, newY - position.y);
        Gdx.app.log("entityMoved()", "newX=" + newX + " - newY=" + newY);
        Gdx.app.log("entityMoved()", "position.x=" + position.x + " - position.y=" + position.y);
    

    and in the main loop, the render() method of ApplicationListener :

    sprite.begin();
    world.draw(sprite);
    sprite.end();
    
    camera.update();
    sprite.setProjectionMatrix(camera.combined);
    

    The draw method() also make my entity move, and notify its observer which is the camera.
    Then I update the camera (not from its own method like I did before) and just update the projectionmatrix.

    A bit laggy, but works like I wanted it to !

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I've just began playing around with the demo of Skeleton, the responsive grid
I am playing around some in C++, just for fun. I have just begun
I just began working with ASP.NET and I'm trying to bring with me some
I've just started playing around with box2dweb and have now run into a problem
I just began using Visual Studio to work on a practice .NET project. I
I just began reading more about Markov Chain Generators today, and am really intrigued
I just began looking into source control.... And installed subversion from collabnet... I also
I just began working on a little twitter-app using tweepy. is there any kind
So just as I began to get a good grasp on MySQL, I found
I have just begun working on a project which uses Mercurial as a version

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.