this just checks if there is a collision at the beginning of the movement? so you could basically just run out of that rectangle you made up for collisions (if you don't stop when you touch it and just keep "w" pressed) cause it just gets checked when you press w and not everytime it changes the position.

this just checks if there is a collision at the beginning of the movement? so you could basically just run out of that rectangle you made up for collisions (if you don't stop when you touch it and just keep "w" pressed) cause it just gets checked when you press w and not everytime it changes the position.

No, I don't change it anywhere. Im trying to fix this maybe 7 hours. I tried a lot of things. What I discovered, is that this jump when I click the button very first time, I tried to block that first push, it worked, but then the movement looked very unnatural and the problem still occured when I pressed two buttons in a row(for example left + up). And the collision doesn't work too. Im so exhausted from this. I would really appreciate if you could help me to achieve what I want: Nice looking movement(I can achieve this) but without that first big jump, which destroys all collision detection.

delayed Key pressing shouldn't be the problem, that would just make the animation delayed too, not make it jump, i guess something with the time might be wrong so that it gets activated too often. Maybe the KeyPressed Event activates the ActionEvent too?

I'm betting this is an artifact of the Swing timer. It's hard to say for sure since you don't show us the imports or extends/implements for your code. There seem to be omitted instance variable declarations as well.

You say that the images appear to move smoothly/correctly. The Swing timer puts the execution of the code on the Event Dispatch Thread (EDT). Maybe, uh...(160-104)/4 = 16 cycles have elapsed and are queued up on the EDT by the time you are inspecting the location variables. There are rules for "collapsing" the contents of the EDT that are a bit too obscure for me to try and figure out if and how they pertain or not.

In general, I think it's better to use a more normal game loop, or use the util Timer, than the swing Timer anyway. The EDT can easily get clogged if you try to accomplish both rendering and game state calculations.

I'd put all the listeners in place BEFORE kicking off the start of the game.

Hard for me to know if this is the right answer though. My understanding of your code is kind of weak, and I tend to avoid the use of the Swing Timer. Maybe you are using a game loop mechanism that is unseen in your code fragment?

"We all secretly believe we are right about everything and, by extension, we are all wrong." W. Storr, The Unpersuadables

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