Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (769)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (855)
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  
  Make invisible body line box2d libgdx  (Read 963 times)
0 Members and 1 Guest are viewing this topic.
Offline Armandotgt

Junior Newbie





« Posted 2017-11-19 23:18:43 »

I want to make these body lines invisible, because it's a lot that was left in the games, and that body circle too. The squares are of a layer tiled map. The circle is a body of a sprite.



Classes draw tiled map

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  
package com.mygdx.game;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.maps.MapObject;
import com.badlogic.gdx.maps.objects.RectangleMapObject;
import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.math.Rectangle;

import com.badlogic.gdx.physics.box2d.World;

public class B2CriaMundo {
   public B2CriaMundo(World mundo, TiledMap mapa) {
         
     
      for(MapObject obj : mapa.getLayers().get(1).getObjects().getByType(RectangleMapObject.class)) {
         Rectangle rect = ((RectangleMapObject) obj).getRectangle();
         
         new Meteoro(mundo, mapa, rect);
         
      }
   }
   
   public static void batida() {
      Gdx.app.log("Bateu:", "");
   }
}


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
package com.mygdx.game;

import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.physics.box2d.Fixture;
import com.badlogic.gdx.physics.box2d.World;

public class Meteoro extends ObjetoInterativo{
   public Meteoro(World mundo, TiledMap mapa, Rectangle bounds) {
      super(mundo, mapa, bounds);
      fixture.setUserData(this);
   }

}


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  
package com.mygdx.game;

import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TiledMapTile;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.Fixture;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.PolygonShape;
import com.badlogic.gdx.physics.box2d.World;

public abstract class ObjetoInterativo {
   protected World mundo;
   protected TiledMap mapa;
   protected TiledMapTile titulo;
   protected Rectangle bounds;
   protected Body corpo;
   protected Fixture fixture;
   
   public ObjetoInterativo(World mundo, TiledMap mapa, Rectangle bounds) {
      this.mundo = mundo;
      this.mapa = mapa;
      this.bounds = bounds;
     
      BodyDef corpoDef = new BodyDef();
      FixtureDef fdef = new FixtureDef();
      PolygonShape shape = new PolygonShape();
     
     
      corpoDef.type = BodyDef.BodyType.StaticBody;
      corpoDef.position.set((bounds.getX() + bounds.getWidth() /2) / ExGame.PPM, (bounds.getY() + bounds.getHeight() /2) / ExGame.PPM);
     
      corpo = mundo.createBody(corpoDef);
     
      shape.setAsBox(bounds.getWidth() /2 / ExGame.PPM, bounds.getHeight() /2 / ExGame.PPM);
      fdef.shape = shape;
      fixture = corpo.createFixture(fdef);
   }
   
}
Offline dime26

JGO Ninja


Medals: 72
Projects: 7
Exp: 12 years


Should traffic wardens be armed?


« Reply #1 - Posted 2017-11-19 23:28:03 »

Are you using the debug renderer to draw these outlines?

You should only use the debug renderer for debugging, maybe use a key to toggle it on / off.
Offline Armandotgt

Junior Newbie





« Reply #2 - Posted 2017-11-19 23:55:24 »

i'am drawing just a tiledmap like world, rectangles appear alone.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline dime26

JGO Ninja


Medals: 72
Projects: 7
Exp: 12 years


Should traffic wardens be armed?


« Reply #3 - Posted 2017-11-20 09:18:40 »

Can you show your render code please
Offline Jperson98

Innocent Bystander





« Reply #4 - Posted 2018-10-08 14:59:29 »

Hey everyone who forget his post or to the new persons. I being looking for this answer a lot. I didn't find it anywhere, but I know found the answer.

When you Make the instance of the Box2DDebugRenderer you should then use the void method setDrawBodies() to false. A show you a little example:

//Box2d variables
private World world;
private Box2DDebugRenderer b2dr;  //Represent all the fetures and bodies indside our 2Dbox World

//Instance of the new World and a new Box2DDebugRenderer
world = new World(new Vector2(0,-10),true);
b2dr = new Box2DDebugRenderer();
b2dr.setDrawBodies(false);  //This method set the body lines to invisible

I hope this could work for everyone who has looking for the answer.

Regards.

Offline cylab

JGO Kernel


Medals: 185



« Reply #5 - Posted 2018-10-09 07:13:21 »

Why using the Box2DDebugRenderer at all, when you don't want to see the outlines?

Mathias - I Know What [you] Did Last Summer!
Pages: [1]
  ignore  |  Print  
 
 

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

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

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

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

nelsongames (1171 views)
2018-04-24 18:15:36

nelsongames (1548 views)
2018-04-24 18:14:32

ivj94 (2305 views)
2018-03-24 14:47:39

ivj94 (1514 views)
2018-03-24 14:46:31

ivj94 (2601 views)
2018-03-24 14:43:53

Solater (878 views)
2018-03-17 05:04:08
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

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
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!