Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (805)
Games in Android Showcase (239)
games submitted by our members
Games in WIP (868)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Newbie & Debugging Questions / Re: Libgdx tiledmap coordinates to screen coordinates? on: 2020-01-14 03:12:54
Hi,i think your OrthographicCamera have some problems when it initialize.
This is a Example for me:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
public class FollowCamera{
   private OrthographicCamera gameCam;
   private Viewport gamePort;

   public FollowCamera(){
      //create camera used to follow hero through camera world
      gameCam = new OrthographicCamera();
      //create a FitViewport to maintain virtual aspect ratio despite screen size
      gamePort = new FitViewport(Configs.viewportWidth / Configs.PPM, Configs.viewportHeight / Configs.PPM, gameCam);
   }

   public void update(Vector2 pos, float zoom){
      // change gameCam zoom
      gameCam.zoom = zoom;
      //attach our gameCam to our players coordinate
      gameCam.position.set(pos.x, pos.y, 0);
      //update our gameCam with correct coordinates after changes
      gameCam.update();
   }

   public OrthographicCamera getCamera(){
      return gameCam;
   }

}

1  
2  
3  
4  
   // Virtual Screen size and Box2D Scale(Pixels Per Meter)
   public static final int viewportWidth = 400;//Pixels
   public static final int viewportHeight = 200;//Pixels
   public static final float PPM = 100;

Configs.viewportWidth / Configs.PPM  --> Viewport width that the camera can see. Unit Meter.
Configs.viewportHeight / Configs.PPM --> Viewport height that the camera can see. Unit Meter.
Virtual Screen and Physical Screen, they're not a same concept.
Virtual Screen   -> Unit Meter.
Physical Screen -> Unit Pixels.
Element's position in the game must be use the 'Meter' such as Hero's position.
Only you are ready to render them, you can transform the 'Virtual Position in Meter' into 'Physical position in Pixels';
Pages: [1]
 
Riven (585 views)
2019-09-04 15:33:17

hadezbladez (5526 views)
2018-11-16 13:46:03

hadezbladez (2406 views)
2018-11-16 13:41:33

hadezbladez (5788 views)
2018-11-16 13:35:35

hadezbladez (1227 views)
2018-11-16 13:32:03

EgonOlsen (4666 views)
2018-06-10 19:43:48

EgonOlsen (5685 views)
2018-06-10 19:43:44

EgonOlsen (3200 views)
2018-06-10 19:43:20

DesertCoockie (4100 views)
2018-05-13 18:23:11

nelsongames (5117 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!