Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (600)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [LibGDX] Camera  (Read 611 times)
0 Members and 1 Guest are viewing this topic.
Offline CelesEternal

Senior Newbie





« Posted 2013-03-27 11:39:00 »

Hello,

Can someone tell me why my map is not rendering in the full camera view?

My code:

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  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
package Module;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.loaders.TileAtlasLoader;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.tiled.TileAtlas;
import com.badlogic.gdx.graphics.g2d.tiled.TileMapRenderer;
import com.badlogic.gdx.graphics.g2d.tiled.TiledLoader;
import com.badlogic.gdx.graphics.g2d.tiled.TiledMap;
import com.badlogic.gdx.math.Vector3;

/**
 *
 * @author Celes Eternal
 *
 */


public class Map {

   /*
    * Data
    *
    */

   
   //Block size
   static final int BLOCK_WIDTH = 32;
   static final int BLOCK_HEIGHT = 32;
   
   //class data
   private TileMapRenderer tileMapRenderer;
    private TiledMap map;
    private TileAtlas atlas;
    private OrthographicCamera cam;
 

    public Map(){
       // Load the tmx file into map
       map = TiledLoader.createMap(Gdx.files.internal("data/testMap.tmx"));

       // Load the tiles into atlas
       atlas = new TileAtlas(map, Gdx.files.internal("data/"));

       // Create the renderer
       tileMapRenderer = new TileMapRenderer(map, atlas,32, 32, 5, 5);
       
       //initialize
       
       cam = new OrthographicCamera(Gdx.graphics.getWidth(),
            Gdx.graphics.getHeight());
 
      cam.position.set(0, 0, 0);
      //cam.translate(Gdx.graphics.getWidth() / -2, Gdx.graphics.getHeight() / -2);
       
    }
   
    public void render() {
       cam.zoom = 1f;
       cam.update();
       
      tileMapRenderer.getProjectionMatrix().set(cam.combined);
     
      Vector3 tmp = new Vector3();
      tmp.set(0, 0, 0);
      cam.unproject(tmp);
     
      tileMapRenderer.render( tmp.x, tmp.y,
            Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
   }
}


Thanks

ps : sorry for my english
Offline Phased
« Reply #1 - Posted 2013-03-27 11:51:09 »

So you create a new topic for the problem, and then go ahead and reply on your old one? logic sense makes.

1  
cam.zoom = 1f;


is useless, the camera will be automatically set to a value, you don't need to set the zoom every frame when its not changing, you only need to change the zoom when it is actually changing.

Your map may be too big for your screen, so you need to move the camera around the world to see it all.

try changing the values in
1  
2  
new OrthographicCamera(Gdx.graphics.getWidth(),
            Gdx.graphics.getHeight());


this can also have a effect (i think, changed some values for mine in a sample i was playing around with to learn LibGDX)
Offline CelesEternal

Senior Newbie





« Reply #2 - Posted 2013-03-27 11:54:27 »

I replied for said thanks ^^
Fo the zoom, i know, it's just because i wanted to put off this without  //
I'll try it after class, thanks
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline CelesEternal

Senior Newbie





« Reply #3 - Posted 2013-03-27 14:03:20 »

I'have tried some combinations but nothing work.

Why?

For me :
1  
2  
3  
4  
cam = new OrthographicCamera(Gdx.graphics.getWidth() ,
            Gdx.graphics.getHeight() );
 
      cam.position.set(0, 0, 0);


Make a camera who start at 0,0,0 and do my all screen , that isn't?

And :
1  
2  
3  
4  
5  
6  
7  
8  
tileMapRenderer.getProjectionMatrix().set(cam.combined);
     
      Vector3 tmp = new Vector3();
      tmp.set(0, 0, 0);
      cam.unproject(tmp);
     
      tileMapRenderer.render( tmp.x, tmp.y,
            Gdx.graphics.getWidth(), Gdx.graphics.getHeight());


Make me a MapRenderer which take the whole screen too, no?
Offline vbrain
« Reply #4 - Posted 2013-03-27 21:03:16 »

I had this problem. You should just pass the camera into the render() mathod

1  
tiledMapRenderer.render(cam);


Libgdx has also changed their tilemap API. Be sure to get the latesst nightly package of libgdx. Read the api here.
Offline CelesEternal

Senior Newbie





« Reply #5 - Posted 2013-03-27 21:27:22 »

Sorry i'm late,
my problem was just that the origin's camera is in the middle of graphics, i was thinking that it was the same but a friend give me this idea and he was right!

But yes use render(cam) is one of solution's parts
Thanks
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (29 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (40 views)
2014-12-09 22:41:13

BurntPizza (76 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (50 views)
2014-12-03 16:27:13

CopyableCougar4 (47 views)
2014-11-29 21:32:03

toopeicgaming1999 (114 views)
2014-11-26 15:22:04

toopeicgaming1999 (102 views)
2014-11-26 15:20:36

toopeicgaming1999 (30 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
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!