Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
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] how to create an infinite level with box2d  (Read 1654 times)
0 Members and 1 Guest are viewing this topic.
Offline grevius
« Posted 2013-09-19 17:51:06 »

hi to all! i use libgdx and box2d in my game and i have a question. I have to do a dinamic level, creted randomly in real time that would be infinite to the right (my is a side scroller game).
How can i do this? how to do this with havent thousand of body in memory for the previous track terrain?
what method i have to implement for create this kind of dinamic randomized level?
thx in advice and have a nice day  Wink Grin
Offline namrog84

JGO Ninja


Medals: 46
Projects: 4


Keep programming!


« Reply #1 - Posted 2013-09-19 22:04:03 »

so lets say, its gonna be a tiled map

there is a few ways that I know of to do this

1st.
each tile or block, is going to have a bodydef associated with it,   keep a Bag Array or something of all of those bodydefs
have it iterate over the array,  checking to see if those bodies/tiles are beyond lets say x < -1000,  then world.remove(thatBodyDef);

2nd.
Have a giant box/line/whatever  to the lefto f the screen x = -1000,  and then setup a custom collision event,  whenever a tile collides with it, remove that tile from the world


3rd.

Have a 'chunk'   each chunk contains lets say 50x50 tiles or whatever.    This way you aren't checking against hundreds or thousands of blocks x position.  Youd just check against 3-10  chunks position.  When the chunk is far enough gone to the left, remove the chunk(and all of its tiles that exist in that chunk)


And on the opposite side of things.
On the positive x > 1000,  you could do almost the exact reverse of the above #1 or #3,   either have a chunk system constantly cycling through chunks or   create a single column of block/tiles/boxes  much more frequently.


For 'randomized level'   depends on what style of dynamic you want.  You could use Simplex or Perlin noise.   Or you could use a 'walking/roughness/windiness' algorithm (http://roguebasin.roguelikedevelopment.org/index.php?title=Basic_directional_dungeon_generation)  Like that, but instead of up/down, implement it to left/right


There are several other ways to handle it, but thats what I would recommend



Recently I implemented the dynamic level, being randomly created in real time, infinite to the right,  using box2d.
http://www.java-gaming.org/topics/escape-copter/30493/msg/281645/view.html#msg281645
play the .jar  and see how it is.
Then you can also look at my sloppy way of implementing it

https://github.com/namrog84/ColorCopterGame/blob/master/CopterGame/src/com/newrog/coptergame/Chunk.java
https://github.com/namrog84/ColorCopterGame/blob/master/CopterGame/src/com/newrog/colorcopter/entities/Block.java

The chunk and the block is whats handling most of whats related to your question.
p.s. If you decide to dive into the code at all,  be mindful it was written hastily and poorly.  There are some 'unused' things and some 'poor approaches' to several things,  However it does work and is functional, and its performance was just fine for what I needed, so I never cleaned it up  Pointing  Huh Undecided Cry




"Experience is what you get when you did not get what you wanted"
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.

pw (22 views)
2014-07-24 01:59:36

Riven (20 views)
2014-07-23 21:16:32

Riven (17 views)
2014-07-23 21:07:15

Riven (20 views)
2014-07-23 20:56:16

ctomni231 (48 views)
2014-07-18 06:55:21

Zero Volt (44 views)
2014-07-17 23:47:54

danieldean (35 views)
2014-07-17 23:41:23

MustardPeter (38 views)
2014-07-16 23:30:00

Cero (53 views)
2014-07-16 00:42:17

Riven (52 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!