Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (517)
Games in Android Showcase (123)
games submitted by our members
Games in WIP (578)
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 1104 times)
0 Members and 1 Guest are viewing this topic.
Offline grevius
« Posted 2013-07-28 10: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: 136
Projects: 4
Exp: 3 years



« Reply #1 - Posted 2013-07-28 16: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
« Reply #2 - Posted 2013-07-28 17: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 Duke


Medals: 9



« Reply #3 - Posted 2013-07-28 17: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 18: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
« Reply #5 - Posted 2013-07-28 20: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 09: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.

DarkCart (16 views)
2014-10-31 21:44:48

DarkCart (22 views)
2014-10-31 21:43:57

TehJavaDev (40 views)
2014-10-27 03:28:38

TehJavaDev (31 views)
2014-10-27 03:27:51

DarkCart (44 views)
2014-10-26 19:37:11

Luminem (27 views)
2014-10-26 10:17:50

Luminem (30 views)
2014-10-26 10:14:04

theagentd (36 views)
2014-10-25 15:46:29

Longarmx (64 views)
2014-10-17 03:59:02

Norakomi (62 views)
2014-10-16 15:22:06
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!