Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (581)
games submitted by our members
Games in WIP (500)
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] Tiled map problem...  (Read 462 times)
0 Members and 1 Guest are viewing this topic.
Offline grevius
« Posted 2013-10-13 22:47:53 »

I, i have a problem with my tiled map, this is a video about it :

 <a href="http://www.youtube.com/v/g-0sAHHqAO0?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/g-0sAHHqAO0?version=3&amp;hl=en_US&amp;start=</a>

My problem is that there are some artefact in my tiled map, but the image haven't that error. I have tryed with lot of tileset, but the result is the same. I've tryed also to use nearest to filter the texture because i read in lot of post that can resolve the problem, but not is changed.
I think that the proble is the precision with the texture il loaded is too high and the opengl fail, i think that the problem is in the camera resolutio/tile with, height but i'm not able to solve it, can somebody help me?
There is 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  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
190  
191  
192  
193  
194  
195  
196  
197  
198  
199  
200  
201  
202  
package com.grevius.Screens;

import net.dermetfan.util.libgdx.box2d.Box2DMapObjectParser;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.maps.MapProperties;
import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TmxMapLoader;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
import com.badlogic.gdx.physics.box2d.Fixture;
import com.badlogic.gdx.physics.box2d.QueryCallback;
import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.utils.ObjectMap;

public class Livello extends InputAdapter implements Screen{

   // Variabili globali
  OrthographicCamera camera;
   World mondo;
   Box2DDebugRenderer renderer;
   OrthogonalTiledMapRenderer mappa;
   
   @Override
   public void render(float delta) {
      Gdx.gl.glClearColor(0, 0, 0, 1);
      Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

      mondo.step(1/45f, 5, 1);
     
      mappa.setView(camera);
      mappa.render();
     
      FollowPlayer();
     
      renderer.render(mondo, camera.combined);
   }

   @Override
   public void resize(int width, int height) {
      float rateo = (float)width/height;
     
      // 4:3
     if(rateo>1.2f && rateo<1.4f) {
         camera.viewportWidth = 800/10;
         camera.viewportHeight = 600/10;
      }
     
      // 16:9      if (rateo>1.6f && rateo<1.9f)
     else {
         camera.viewportWidth = 854/10;
         camera.viewportHeight = 480/10;
      }

      MapProperties prop = mappa.getMap().getProperties();

      int mapWidth = prop.get("width", Integer.class);
      int mapHeight = prop.get("height", Integer.class);
      int tilePixelWidth = prop.get("tilewidth", Integer.class);
      int tilePixelHeight = prop.get("tileheight", Integer.class);
     
      camera.position.set(10*mappa.getUnitScale()*tilePixelWidth, 11*mappa.getUnitScale()*tilePixelHeight, 0);
//      camera.position.set(mapWidth*tilePixelWidth/2*mappa.getUnitScale(), mapHeight*tilePixelHeight/2*mappa.getUnitScale(), 0);
     camera.update();
     
      Gdx.app.log("INFO", "dim : " + width + " " + height);
   }

   @Override
   public void show() {
      // Inizzializzo la camera
     camera = new OrthographicCamera();
     
      Gdx.input.setInputProcessor(this);
     
      // Inizializzo il mondo
     mondo = new World(new Vector2(0, -9.81f), true);
      renderer = new Box2DDebugRenderer();
     
      TmxMapLoader.Parameters par = new TmxMapLoader.Parameters();
      par.textureMinFilter = TextureFilter.Nearest;
      par.textureMagFilter = TextureFilter.Nearest;
     
      TiledMap level = new TmxMapLoader().load("data/prova.tmx", par);
      mappa = new OrthogonalTiledMapRenderer(level, 0.20f);
     
      Box2DMapObjectParser parser = new Box2DMapObjectParser(0.20f);
      parser.load(mondo, level);
     
      ObjectMap<String, Body> corpi = parser.getBodies();
      corpo = corpi.get("Player");
   }

   @Override
   public void hide() {
      this.dispose();
   }

   @Override
   public void pause() {
      // TODO Auto-generated method stub

   }

   @Override
   public void resume() {
      // TODO Auto-generated method stub

   }

   @Override
   public void dispose() {
      mondo.dispose();
      renderer.dispose();
      mappa.dispose();
   }

   
   private void FollowPlayer() {
      float lerp = 0.1f;
      Vector3 position = camera.position;

      position.x += (corpo.getPosition().x - position.x) * lerp;
      position.y += (corpo.getPosition().y - position.y) * lerp;

      camera.position.set(position);
      camera.update();
     
   }
   
   // Vettore per la posizione del tocco
  private Vector3 pos = new Vector3(), tmp = new Vector3();
   private Vector2 forza = new Vector2();
   private Body corpo;
   private boolean toccato = false;
   
   private QueryCallback queryCallBack = new QueryCallback() {
     
      @Override
      public boolean reportFixture(Fixture fixture) {
         // Controllo se c'è veramente un corpo
        if(!fixture.testPoint(pos.x, pos.y))
            return false;
         
         corpo = fixture.getBody();
         toccato = true;
         Gdx.app.log("INFO", "nome : " + fixture.getBody().isAwake());
         
         return false;
      }
   };
   
   
   @Override
   public boolean touchDown(int screenX, int screenY, int pointer, int button) {
      // Imposto dove è stato dato il tocco nelle unità del mondo
     camera.unproject(pos.set(screenX, screenY, 0));
     
      mondo.QueryAABB(queryCallBack, pos.x, pos.y, pos.x, pos.y);
      return true;
   }
   

   @Override
   public boolean touchUp(int screenX, int screenY, int pointer, int button) {
     
      if(toccato) {
         forza.limit(20);
         if(!corpo.isAwake())
            corpo.setLinearVelocity(forza);
         Gdx.app.log("INFO", "nome : " + corpo.getUserData());
      }
     
      toccato = false;
     
      return true;
   }
   

   @Override
   public boolean touchDragged(int screenX, int screenY, int pointer) {
     
      // Se ho toccato il player imposto la forza con cui esso si può lanciare
     if(toccato) {
         tmp.set(screenX, screenY, 0);
         camera.unproject(tmp);
         
         forza.set(pos.x-tmp.x, pos.y-tmp.y);
      }
     
      return true;
   }

}
Offline ShuKen

Junior Member


Medals: 4



« Reply #1 - Posted 2013-10-13 23:13:43 »

Try using int positions for the camera instead of float...maybe is that. I had similar issues few time ago.
Offline grevius
« Reply #2 - Posted 2013-10-13 23:19:30 »

if i use int for the camera it move too laggy, and is not the best movement.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ShuKen

Junior Member


Medals: 4



« Reply #3 - Posted 2013-10-13 23:52:42 »

Mmh...I use ints just for the camera and works well. The rest of the calculus uses floats.
After all, the screen is in pixels. And you cant draw something on the pixel "150.34544f". Its just 150 (I guess).

Maybe you have another problem here, but I repeat, i had a similar issue and fixed it when starting using ints. Just a comment. If it doesn't work then must be something else.
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.

xsi3rr4x (55 views)
2014-04-15 18:08:23

BurntPizza (53 views)
2014-04-15 03:46:01

UprightPath (66 views)
2014-04-14 17:39:50

UprightPath (49 views)
2014-04-14 17:35:47

Porlus (66 views)
2014-04-14 15:48:38

tom_mai78101 (90 views)
2014-04-10 04:04:31

BurntPizza (151 views)
2014-04-08 23:06:04

tom_mai78101 (246 views)
2014-04-05 13:34:39

trollwarrior1 (204 views)
2014-04-04 12:06:45

CJLetsGame (211 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!