Home Game Development LibGdx Positioning the digicam – Game Development Stack Exchange

LibGdx Positioning the digicam – Game Development Stack Exchange

0
LibGdx Positioning the digicam – Game Development Stack Exchange

[ad_1]

I have never ever used LibGDX, however what you may need to do is use the width of the digicam viewport, and restrict the x place of the digicam like this pseudocode:

digicam.x = min((levelWidth / 2) + levelPosition.x - (digicam.viewportWidth / 2), digicam.x);

Essentially, we discover the smaller quantity with the min perform, which can restrict our digicam.x worth to the x place of the place the digicam may be and never present any of the skin of the extent. The OrthographicCamera class from LibGDX gives the viewportWidth worth, so that you solely have to be sure you know the place your degree object is positioned and the way vast it’s.

That code with stop you from having the digicam go too far to the suitable, to forestall it going to far too the left, use an implementation just like:

digicam.x = max(-(levelWidth / 2) + levelPosition.x + (digicam.viewportWidth / 2), digicam.x);

This does an analogous factor to the unique, it simply ensures that the digicam’s left certain by no means goes additional left than the leftmost level on the extent. Both of those snippets assume that the place of the extent is in its heart. If the extent is at (0, 0), then the levelPosition.x may be omitted utterly:

digicam.x = min((levelWidth / 2) - (digicam.viewportWidth / 2), digicam.x);
digicam.x = max(-(levelWidth / 2) + (digicam.viewportWidth / 2), digicam.x);

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here