Hello, I'm working on a top down 2d game and am having some problems with collision detection. Here is a basic screenshot.

My issue involves buggy movement. If I spam movement keys near a wall, I can pass through and get stuck. I think my problem may be related to multiple threads, but I am not sure.

I have a text file grid of integers read in for collision, 1 = not passable, 0 = passable. My checkCollision function checks the proposed new player position for a collision, and disallows that movement if there is a tile.

Somewhere in here there is a bug going on. I know the detectcollision method is working properly as I debugged it with println's. It seems that sometimes, while I am actively "Moving", my direction can change and place me in a wall. Note that this code has double collision checking, I tried with one and it simply let me into impassable walls, with two checks i actually get stuck in the wall and cant move at all.

Can anyone help me out here. Is there a simpler way of getting animated tile movement?

Is that theChernoProject? If it is, I have to say he's an ok programmer, but one thing that has always bugged me is his use of threads. You don't need to manually create a thread just to start a game. There is absolutely (as far as I know) no advantage to it, and it really isn't a good design.

You need to create a separate thread for your game when you're using JFrame. If you don't, you will have problems with JFrame.

The great tutorial maker arrives! I was just reading your tutorial linked above! Thanks for it, I'm just fiddling with the LWJGL keyboard stuff there.

Also, how would I go about making a seperate thread for my jframe? I have no experience with threads really.Here is my main, which pretty much just makes a frame and launches it. I assume I would have to modify this?

Thanks to the tutorial, I figured it out. In the end I ran into a simple semantics problem.The code above references a "CanMove" method which checks a tile to see if the player can move there, while my collision layer was using the term "DetectCollision".

It took me a bit to figure out that (CanMove = true) != (DetectCollision = true). One says "yes you can move there", the other says "yes there is a collision".

Now I am trying to alter this new movement method so I can have similar movement as before. IE: Press button,ignore input, move player image a few pixels, repeat for X ticks until centered on a tile, allow input again.

Also! I noticed a slight bug in the tutorial code, which was mentioned. Even if the player wasnt moving, it continued to call the CanMove functions a total of 10+ times every tick.

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