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  
  Question about TileMap and Tiled  (Read 650 times)
0 Members and 1 Guest are viewing this topic.
Offline Bassex96

Senior Member


Medals: 4



« Posted 2013-04-25 04:54:08 »

Hey guys, i'm moving on to a 2d tiled game..I've been reading through some old tutorials and information pages..It seems tilemap has changed a bit, i'm trying to put everything together to come up with something. One question I have though..I have my tileset already put together, do I need to pack the texture?

I've already loaded the tileset into Tiled and made a small level. I'm still trying to decipher the information available, if anyone has any good 'current' tutorials it would be greatly appreciated.
Offline Bassex96

Senior Member


Medals: 4



« Reply #1 - Posted 2013-04-25 20:00:14 »

I've got the camera working and showing my map, but everything looks zoomed in. I've gone through the wiki and can't seem to find how to keep the tiles at 16x16 instead of stretching or zooming them..I can zoom in and out, but that doesn't solve the stretching problem...

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  
package com.bassex.oasishm;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.tiled.*;

public class OasisGame implements ApplicationListener {
   private OrthographicCamera camera;
   private SpriteBatch batch;
   private Texture texture;
   private Sprite sprite;
   
   TileMapRenderer mapRenderer;
   TileAtlas atlas;
   TiledMap map;
   
   static final int WIDTH = 800;
   static final int HEIGHT = 600;
   
   @Override
   public void create() {      
      float w = Gdx.graphics.getWidth();
      float h = Gdx.graphics.getHeight();
     
     
      camera = new OrthographicCamera(HEIGHT,WIDTH);
      batch = new SpriteBatch();
     
      //Map Stuff
     
      map = TiledLoader.createMap(Gdx.files.internal("data/testlvl.tmx"));
      atlas = new TileAtlas(map, Gdx.files.internal("data"));
      mapRenderer = new TileMapRenderer(map, atlas, 8, 8);
     
     
     
      //camera.position.x = WIDTH / 2;
     //camera.position.y = HEIGHT / 2;
     camera.setToOrtho(false, WIDTH / 2,HEIGHT / 2);
     
   }

   @Override
   public void dispose() {
      batch.dispose();
      texture.dispose();
   }

   @Override
   public void render() {      
      Gdx.gl.glClearColor(1, 1, 1, 1);
      Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
     
     
      if(Gdx.input.isKeyPressed(Keys.LEFT)){
         camera.position.x=camera.position.x-Gdx.graphics.getDeltaTime()*300;
      }
      if(Gdx.input.isKeyPressed(Keys.RIGHT)){
         camera.position.x=camera.position.x+Gdx.graphics.getDeltaTime()*300;
      }
      if(Gdx.input.isKeyPressed(Keys.DOWN)){
         camera.position.y=camera.position.y-Gdx.graphics.getDeltaTime()*300;
      }
      if(Gdx.input.isKeyPressed(Keys.UP)){
         camera.position.y=camera.position.y+Gdx.graphics.getDeltaTime()*300;
      }
      if(Gdx.input.isKeyPressed(Keys.PLUS)){
         camera.zoom-=Gdx.graphics.getDeltaTime();
      }
      if(Gdx.input.isKeyPressed(Keys.MINUS)){
         camera.zoom+=Gdx.graphics.getDeltaTime();
      }      
     
     
      camera.update();
      mapRenderer.render(camera);  
   }

   @Override
   public void resize(int width, int height) {
   }

   @Override
   public void pause() {
   }

   @Override
   public void resume() {
   }
}



I'm trying to find a good TiledMap tutorial but haven't had much luck as it seems TiledMap has been changed...so I don't know what is correct and incorrect on the tutorials I can find..I'm not even sure HOW to begin drawing my character into the map or anything..Does anyone have any good tutorials for this or any good information? It would be greatly appreciated.
Offline Bogdan

Senior Newbie


Projects: 1



« Reply #2 - Posted 2013-04-25 20:24:06 »

1  
camera.setToOrtho(false, WIDTH / 2,HEIGHT / 2);


This takes width and height, so it should be WIDTH and HEIGHT, not WIDTH / 2 and HEIGHT / 2 if I understood Your problem correctly.

About tutorials, I do not know any, examples are best tutorials Smiley
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Bassex96

Senior Member


Medals: 4



« Reply #3 - Posted 2013-04-25 20:40:03 »

Yeah, I don't think i'm using that method correctly..But when I removed the /2, it screwed everything up. Now the map is very small.

This isn't the problem i'm having though. I've been looking over it a bit more and I think my problem has to do with clipping. I want the tiles and map to stay one size, even when it's resized. The tiles are stretched and are bigger than 16 pixels. I've played with the zooming a bit and got it to look right, but when I resize the window, they just stretch..
Offline Axeman

Senior Member


Medals: 7



« Reply #4 - Posted 2013-04-26 15:27:31 »

I´m not really sure I understand your problem, but the way you describe it is the way it´s supposed to behave. If you resize your window everything will scale to the new resolution.

One thing that is important to understand is that you´re actually not loading 16x16 pixels that you can plot to the screen: You´re loading a texture that is pasted on a rectangle. A rectangle doesn´t have "pixel size", just coordinates, and will clamp the image within these coordinates .This mean that when you resize the window, you also scale the rectangle (= sprite) to fit the new window resolution and since texture coordinates are relative to the rectangle you´ll also scale the texture. Hence, everything will stretch.

So if what you are experiencing are that the "stretch ratio" of the tile is equal to the new window size, this is expected. You may not like it but it is normal. If not, I think you need to clarify your problem.
Offline Bassex96

Senior Member


Medals: 4



« Reply #5 - Posted 2013-04-26 22:18:16 »

Yeah, sorry, it's a bit hard to explain. Basically, I want it so if I were to make the window bigger it would show more of the map..Not stretch what is already on the map. I want everything to stay one size.
Offline Axeman

Senior Member


Medals: 7



« Reply #6 - Posted 2013-04-26 23:50:43 »

Try adding this to your resize method:

1  
2  
3  
public void resize(int width, int height) {
   camera.setToOrtho(false, width, height);
}


This should set the viewport to the same size as the window.
Offline Geemili

Senior Member


Medals: 9
Projects: 1
Exp: 2 years


No Games Finished


« Reply #7 - Posted 2013-04-26 23:58:37 »

I think he wants the game to scale, but not stretch. If so, I think that this is a solution.
Offline Axeman

Senior Member


Medals: 7



« Reply #8 - Posted 2013-04-27 00:12:54 »

I think he wants the game to scale, but not stretch. If so, I think that this is a solution.

Tried it. Didn´t stretch.
Offline Bassex96

Senior Member


Medals: 4



« Reply #9 - Posted 2013-04-27 03:03:50 »

It does..I just resized the window. My code is a little different than what I posted earlier but not much.

Thanks Geemili, that helps.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Axeman

Senior Member


Medals: 7



« Reply #10 - Posted 2013-04-27 03:37:14 »

I meant I tried my little snippet and it didn´t stretch... But all is well that ends well!  Grin
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 (57 views)
2014-04-15 18:08:23

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

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

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

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

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

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

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

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

CJLetsGame (212 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!