Help with tile centering

Hello all!

I’m making a game for the Traffic Jam (which I hope will come soon!) and I’m stuck on something.
My game allows you to switch lanes, using the up or down keys. But it’s really easy to crash into a car by 1 pixel, which can be very annoying. So, I’m in the process of implementing smooth lane changing, so it will change to the next lane and align perfectly, instead of having you to align it yourself, kinda like a really expensive car that lane changes for you. :wink:

For some reason, changing lanes down (right if you hold it at 270) is perfectly fine, while changing lanes up (left), it will not align to the road. I for the life of me cannot understand why my game is doing this to me and you are all smarter than me. :wink:

Here is the troubling game:
(All the controls should be explained in the start screen - if you don’t get it just ask!)

I also remember this code (by reyhanPanci256):

from this thread:

but it doesn’t seem to work in this version :frowning:

Hi,

I’m going to write down the process of debugging and fixing with blurring.

It’s always:

  1. to reproduce the bug in a simplified scenario;
  2. locate the cause
  3. fix

For step 1, read the code, find the code relevant and remove those not to make testing quick and easy. (I removed the slow cars, which interrupts testing(causing game over)


After that I’m able to test up / down;

Step 2, locate the bug with logging, logging is the cheapest and easiest way for straightforward bugs. This time, its obvious that y of car is not correct updated after up is released, so I add some logs:


Also, as you mentioned, releasing down works fine, so we may want to compare them for a better understanding, that’s why logs are added to down releasing event.

Now I can reproduce with logging,

Try to locate the cause now.

Hint:

The changes to y for up / down should not be the same, consider the following:
Let’s suppose the of y of car is now 28,
a.) for moving up, y should be set to ?
b.) for moving down, y should be set to ?

Hope it helps.

2 Likes

Thank you felixtsu!
I’m currently not at my computer, so I can’t run through the whole debugging thing.
Thank you again for the time and effort you out into helping me!
It’s so tempting just to unblur the hint ! Agh!

1 Like

Got it to work! Thank you so much for helping me with my game!
BTW, you accidentally put the answer when you were showing me this photo:
image
It includes the 16 -

2 Likes

Here’s the game if anyone wants to try it out:

3 Likes

Oops! :rofl:

1 Like

Animated title screen is :fire:. Fun/challenging gameplay too!

(Seriously love that text layout on the title screen…)

2 Likes

Thank you! Writing the text took forever :sweat_smile:
I got the idea from a mobile game that I really liked and decided to create the game in Traffic/Car theme so I could submit it to the Traffic Jam!

Oh, that snake game thing?

A different game.

which one?

Here’s my record

1 Like