Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (744)
Games in Android Showcase (225)
games submitted by our members
Games in WIP (825)
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 How should i render a random generated map on: 2017-05-14 15:23:58
I have read that but do not understand
Help?
thx tho
2  Game Development / Newbie & Debugging Questions / Re: LibGDX How should i render a random generated map on: 2017-05-14 12:46:49
If you need more info just ask. Thanks
3  Game Development / Newbie & Debugging Questions / LibGDX How should i render a random generated map on: 2017-05-14 12:45:35
Hello first thing first i want to say i am VERY! New to coding,game dev, and java so be nice if the fix is very easy.

I got the generater form here: http://javagamexyz.blogspot.com.au/2013/03/terrain-generation.html

Ok my ? is how should i render. Some thing like
1  
2  
3  
4  
5  
6  
7  
MidpointDisplacement md = new MidpointDisplacement();
      temp = md.getMap();
      for(int row = 0; row < temp.length; row++) {
         for(int col = 0; col < temp[row].length; col++) {
         }
           
      }

But what should i use to render (what do i add the texters to?)

All help is welcomed.

Thank You
4  Game Development / Newbie & Debugging Questions / Re: LibGDX Tmx file not rendering. on: 2017-04-29 13:15:14
Fixed it
The PPM was a int and unlease it was set to 1 it did not render
it needs to be a float. My Bad idk that Grin

Thx CopyableCougar4 if you did not send that link I would still have problems
5  Game Development / Newbie & Debugging Questions / Re: LibGDX Tmx file not rendering. on: 2017-04-28 21:07:56
If anyone need's more info just ask  Grin
6  Game Development / Newbie & Debugging Questions / LibGDX Tmx file not rendering. on: 2017-04-28 13:20:09
Hello i'm making a platformer for practice and have run into a problem. I'm using Tiled for the map and eclipse for code.

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  
package com.pumkin.treejumper;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.pumkin.screens.GameScreen;

public class treeJumper extends Game {
   public SpriteBatch batch;
   
   public int PPM = 3;
   public int Game_W = 100;
   public int Game_H = 100;
   
   @Override
   public void create () {
      batch = new SpriteBatch();
     
      setScreen(new GameScreen(this));
   }

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


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  
package com.pumkin.screens;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.maps.MapObject;
import com.badlogic.gdx.maps.objects.RectangleMapObject;
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.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.PolygonShape;
import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
import com.pumkin.treejumper.treeJumper;

public class GameScreen implements Screen {
   
   private treeJumper game;
   private OrthographicCamera cam;
   private TmxMapLoader mapLoader;
   private TiledMap map;
   private OrthogonalTiledMapRenderer Renderer;
   private World world;
   private Box2DDebugRenderer b2dr;
   private Texture img;

   public GameScreen(treeJumper game) {
      this.game = game;
     
      //Cam and Vport
      cam = new OrthographicCamera();
      cam.setToOrtho(false, game.Game_W / game.PPM, game.Game_H / game.PPM);
      cam.update();
   
      img = new Texture("grass.png");
     
      //Tmx map loading and renderer
      mapLoader = new TmxMapLoader();
       map = mapLoader.load("TestMap.tmx");
       Renderer = new OrthogonalTiledMapRenderer(map, 1 / game.PPM);
     
       //Box2d
       world = new World(new Vector2(0, 0), true);
       b2dr = new Box2DDebugRenderer();
       
       BodyDef bdef = new BodyDef();
       PolygonShape shape = new PolygonShape();
       FixtureDef fdef = new FixtureDef();
       Body body;
       
       for(MapObject object : map.getLayers().get(0).getObjects().getByType(RectangleMapObject.class)) {
          Rectangle rect = ((RectangleMapObject) object).getRectangle();
         
          bdef.type = BodyType.StaticBody;
          bdef.position.set((rect.getX() + rect.getWidth() / 2) / game.PPM, (rect.getY() + rect.getHeight() / 2) / game.PPM);
         
          body = world.createBody(bdef);
         
          shape.setAsBox((rect.getWidth() / 2) / game.PPM, (rect.getHeight() / 2) / game.PPM);
          fdef.shape = shape;
          body.createFixture(fdef);
       }
     
     
   }

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

   public void update(float dt) {
      cam.update();
     
      world.step(1/60f, 3, 3);
     
     
      if(Gdx.input.isKeyPressed(Keys.A)) cam.position.x += -1;
      if(Gdx.input.isKeyPressed(Keys.W)) cam.position.y += 1;
      if(Gdx.input.isKeyPressed(Keys.D)) cam.position.x += 1;
      if(Gdx.input.isKeyPressed(Keys.S)) cam.position.y += -1;
   }
   
   
   
   @Override
   public void render(float dt) {
       update(dt);
       
       Gdx.gl.glClearColor(0.5f, 0.4f, 1, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
       
       Renderer.render();
       Renderer.setView(cam);
       
       game.batch.setProjectionMatrix(cam.combined);
       game.batch.begin();  
       game.batch.draw(img, 0, 0);
       game.batch.end();
       
       b2dr.render(world, cam.combined);
       System.out.println(Gdx.graphics.getFramesPerSecond());
   }

   @Override
   public void resize(int width, int height) {
      // TODO Auto-generated method stub
     
   }

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

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

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

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

}


Output:

(Hope it worked but if it did not it just shows Box2d debug lines)

I'm new to java/coding so all help in nice and Thank you.
Pages: [1]
 
Ecumene (149 views)
2017-09-30 02:57:34

theagentd (222 views)
2017-09-26 18:23:31

cybrmynd (301 views)
2017-08-02 12:28:51

cybrmynd (288 views)
2017-08-02 12:19:43

cybrmynd (297 views)
2017-08-02 12:18:09

Sralse (291 views)
2017-07-25 17:13:48

Archive (978 views)
2017-04-27 17:45:51

buddyBro (1102 views)
2017-04-05 03:38:00

CopyableCougar4 (1678 views)
2017-03-24 15:39:42

theagentd (1430 views)
2017-03-24 15:32:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
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!