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 (530)
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] Collision detection and come back at the last position?  (Read 1191 times)
0 Members and 1 Guest are viewing this topic.
Offline SrFurias

Senior Newbie





« Posted 2013-07-02 17:27:17 »

I'm building a platformer game with libGDX, I have learned Draw images, build user interface, and other things how input, outputs , etc but I can't find a class or other for do the collision detection and when any thing collide with other (one can't move, like the ground) and come back to the last position, for simulate a wall or something like it.

And how can I put gravity in mi game. I tryed do it with Box 2D but I need learn first more of libGDX, because Box 2D have things dot I don't know how do it.

I don't know if you are understand this, because I'm spanish.

Thanks.
Offline 65K
« Reply #1 - Posted 2013-07-02 18:27:27 »

So you are a beginner, already using Libgdx, need collision handling and gravity, then you definitely should use Box2D. Learning it will be much faster (even if does not seem so now) and the results most likely much better (no offense) than breeding your own stuff.

Offline Meitnerium109

Junior Member


Projects: 2



« Reply #2 - Posted 2013-07-02 18:50:07 »

So you are a beginner, already using Libgdx, need collision handling and gravity, then you definitely should use Box2D. Learning it will be much faster (even if does not seem so now) and the results most likely much better (no offense) than breeding your own stuff.

Actually, in my humble opinion, I don't think box2D would make it easier for a beginner. I've personally attempted to use box2D solely for collision, but it didn't turn out to be easier than if I wrote my own collision detection. If you're using circles or complex polygons, or if you want to simulate real physics, then definitely go with box2D, but it certainly does come with a lot of learning about the api and such. If you're only using rectangles for collision and don't need to simulate real physics, then you're better of writing your own collision detection. It's not too hard to do, and it doesn't come with the amount of content and possible bugs that will come when using box2D.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline 65K
« Reply #3 - Posted 2013-07-02 19:47:55 »

A common characteristic of all developers is to underestimate efforts.

Offline tyeeeee1
« Reply #4 - Posted 2013-07-02 19:53:34 »

Just try messing around until you figure out how to create collision detection. It took me a while but I finally figured out a way that worked by creating four points around my player and then checking if any of the four points were inside of a tile that they shouldn't be; after that I just adjusted the X and Y values of my character until the four point check came back saying that he wasn't inside of the tile anymore. This way is probably nowhere near the best way to do collision detection but it was pretty easy for me. =P
Offline Meitnerium109

Junior Member


Projects: 2



« Reply #5 - Posted 2013-07-02 20:31:42 »

The way I first did collision was something like (Assume character collides with a box):

1) Move the character according to the Y speed
2) Check for collision, if collision occurs, check the Y speed of the character, and then move it accordingly (if it is moving down, move the character to the top of the box, etc. This assumes that the speed of Y and all calculations that affect the speed of Y be done before the collision detection)
3) Move the character according to the X speed
4) Check for collision, if collision occurs, check the X speed of the character, then move it accordingly (Same assumptions as above).

Works well for what I'm trying to do.
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 128
Projects: 4
Exp: 3 years



« Reply #6 - Posted 2013-07-04 04:09:09 »

Box2D is not that difficult, you just need to have a clear understanding of how scaling works and how the different objects interact. You really don't need to know much libgdx to implement box2d, it's just an addon to libgdx.
Offline heisenbergman

JGO Coder


Medals: 14


L___ o_ G___ a__ P___


« Reply #7 - Posted 2013-07-04 04:46:38 »

So you are a beginner, already using Libgdx, need collision handling and gravity, then you definitely should use Box2D. Learning it will be much faster (even if does not seem so now) and the results most likely much better (no offense) than breeding your own stuff.
Seconded.

I just started studying game development around 10 weeks ago and my learning project is currently also a 2D platformer with LibGDX and using Box2D. There is some difficulty involved in learning it and wrapping your head around some concepts (particularly those that Jimmt mentioned) but nothing that should take too long.

Ultimately, the time you will be spending learning Box2D will pay its dividends a hundredfold as you continue developing your game since Box2D is a powerful tool in terms of controlling how objects act and interact with each other.

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 (11 views)
2014-07-24 01:59:36

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

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

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

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

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

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

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

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

Riven (50 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!