(like ndenarodev mentioned) If for example the 'current camera position' is 1.1 - make the 'aim camera position' 1.0; And only change the current camera position if the camera should move. If the aim camera position is something else than transform.position - set transform.position (of your camera) to 'aim camera position'. Your problem is, that you set the same cam to the stage and the rest of your game. A libgdx Stage has its own camera.You should use this, as this camera won't move arround. So you have your camera and your SpriteBatch to render the game and the Stages cam and SpriteBatch to render the UI over it. Just make sure you call spriteBatch.end; before calling stage.draw, because if two.
I'm about to start developing a sidescrolling game where the player's goal is to travel as far as he can in the horizontal axis before touching down. Note that I do not need to ever travel back on the horizontal axis.
I'm developing this with the AndEngine for Android which uses OpenGL and Box2d.
Before starting, I need to decide on something important: should I use the world around the player to simulate movement or actually move the player and follow him with the camera features of the game engine?
Both approaches seems to have different strengths and fallbacks, so I don't know which one is considered best. For example, what would make it easier to add power ups along the way and have a nice animated background?
Thanks!
It's pretty trivial really, it doesn't really make a difference from the things you've described.
Either you move the background past the camera and the player, or you move the player and the camera with him. I suppose there's one less thing to do if you just move the background.
Although I suppose if you move the background you'll have to parent any pickups and enemies to that, which again, is trivial but it's something to think about.
Personally I would move the player because I just like things to be done in a more realistic way.
Move the camera (attached to your player). I would imagine that your world has multiple objects such as enemies. If you went with moving the world, you would have to loop through all these objects to update their positions every time the world moved.
If you move the player, and attach the camera to the player then there is minimal resource usage. The game will get to its render phase, loop through everything once like it does every frame, and draw them at position - camera.position. Camera position would always equal your players position in this case.
I always move the camera and would recommend it - there are many reasons why I prefer this, but the most significant probably boils down to this:
If you move the camera and player, that's only two entities that need to be updated to scroll the screen.
If you move the entire world whenever the screen needs to scroll, that encompasses an unknown and possibly large number of entities that will have to be updated.
Related Questions
How to infinitely repeat background with parallax scrolling in Libgdx?
Updated March 21, 2017 07:13 AM![Move Only Camera Libgdx Move Only Camera Libgdx](https://pbs.twimg.com/media/CvkRAezUsAAlt1c.jpg)
Touch pad controls not working in apk, working from Unity Remote
Updated March 26, 2015 07:26 AMSide scroller terrain generating and scrolling
Updated April 15, 2019 00:13 AMLibGDX - Best way of scrolling background
Updated April 10, 2015 22:05 PMHow to make camera follow the sprite when moving using accelirometer and extend background? in libgdx
Updated March 16, 2017 05:13 AMBasically I wrote a 'Dota like Style' based on the OrthographicCamera
from libgdx.You can test it out for youself here is the class.
I am using this to draw a TiledMap, and I have and array of tiles corresponding with the graphical tiles, however if I move the mouse, and with that the camera.
The coordinates off the mouse and the tiles are completely different.Gdx.input
x and y get their coordinates relative to the screen and not where the mouse is in the world relative to the camera.
I can't figure out a way to get the mouse position relative to the camera, so that if I move the camera I won't just get the regular mouse coordinates, but the actual world coordinates that the camera is showing, and where my mouse is located within the confines of the view of the camera relative to the world.
2 Answers
Came across this problem and discovered the answer here:
Supposedly, using Camera.unproject(Vector3 screenCoords)
is the correct way of doing this.
![Orthographic camera Orthographic camera](https://i.stack.imgur.com/Rsyuh.gif)
My solution looks like this:
I hope you found the solution to what you need herehttps://gamedev.stackexchange.com/questions/60703/libgdx-how-to-get-mouse-position-relative-to-a-tiled-mapmaybe hereGet cursor position in LIBGDXor herehttp://www.netthreads.co.uk/2012/01/31/libgdx-example-of-using-scene2d-actions-and-event-handling/