Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (429)
Games in Android Showcase (89)
games submitted by our members
Games in WIP (468)
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] Custom Box2D shape creation problem  (Read 693 times)
0 Members and 1 Guest are viewing this topic.
Offline grevius
« Posted 2013-07-28 12:27:57 »

Hi! I have a tmx file that contains all my level stuff.
In a layer i have created one polyline that is the border of all ground level, but my problem is transform my polyline in a box2D body.
Someone can suggest me a tutorial or a method to do this?
thanks in advice Smiley
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 119
Projects: 4
Exp: 3 years



« Reply #1 - Posted 2013-07-28 18:56:24 »

Take a look at the Physics Body Editor, it can autotrace shapes and has its own loader (not integrated with tiled maps, however).
Offline sirkarpfen

Junior Member


Medals: 2



« Reply #2 - Posted 2013-07-28 19:07:24 »

As far as i know libgdx, you cannot get the vertices you need to create a Box2d-Shape directly from a MapObject. You can only get the Properities from the specific object.

So you can either store the vertices in your MapObjects properties, or you hardcode them.

To create a ground in your game you can use the ChainShape as specified here:
Libgdx JavaDoc

A nice Tutorial on how to create a ground with ChainShape:
http://www.youtube.com/watch?v=BEyu55aDhkY

Another possibility is to create a meta-data layer an color the tiles, you want to collide with. Then you can get the TiledMapTileLayer and from that get the Cell that is not null. This only works for box shaped grounds so maybe ChainShape fits you better in this case Smiley.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline nexsoftware

Junior Member


Medals: 9



« Reply #3 - Posted 2013-07-28 19:19:54 »

If the MapObject is created from a "polyline" in Tiled, it will be a PolylineMapObject and if you cast it as such you can get the vertices.
Offline grevius
« Reply #4 - Posted 2013-07-28 20:31:32 »

If the MapObject is created from a "polyline" in Tiled, it will be a PolylineMapObject and if you cast it as such you can get the vertices.
it's interesting, after i get the verticle how i have to do for transforn the coordinates in a body?
really thanks for all reply!
Offline sirkarpfen

Junior Member


Medals: 2



« Reply #5 - Posted 2013-07-28 22:43:54 »

If the MapObject is created from a "polyline" in Tiled, it will be a PolylineMapObject and if you cast it as such you can get the vertices.

Thank you very much, i didn't know that Smiley.
Offline grevius
« Reply #6 - Posted 2013-07-29 11:18:54 »

i'm not able to cast in PolylineMapObject and i don't find nothing on internet about this  Cry if somebody knows how it can be doing please write below  Grin

ok, i found how to do, here is the code :
1  
2  
3  
4  
PolylineMapObject polyline= (PolylineMapObject) map.getLayers().get("Layer_Name").getObjects().get("Polyline_Name");

for(int i=0; i<polyline.getPolyline().getVertices().length; i++)
   Gdx.app.log("INFO", "VAL : " + verticles[i]);
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.

theagentd (6 views)
2014-04-24 23:00:44

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

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

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

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

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

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

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

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

trollwarrior1 (216 views)
2014-04-04 12:06:45
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!