Rectangle (Axe) is not moving up-down but just flickering at the same place!

Greetings!

My rectangle(axe) is flickering at the same place instead of moving up and down. I cannot figure out the issue with my code. May I get any help? I understand the issue lies within line(25-29). If I change the right side of the logical or to rectangleY < 0, the program works fine. But it doesn’t work for any other value; for instance, what if I want to set the upper boundary for my rectangle at y = 50 or 100?

I appreciate any help you can provide.

Something to ponder, if rectangleY starts at 0, then is rectangleY < 50 always true by the next frame? If we try doing a manual trace of lines 25 and 26 for a few frames…

0 + 5 = 5
Great than 718? False, Less than 50? True. Result: True, flip direction
5 - 5 = 0
Great than 718? False, Less than 50? True. Result: True, flip direction
0 + 5 = 5
Great than 718? False, Less than 50? True. Result: True, flip direction
5 - 5 = 0
Great than 718? False, Less than 50? True. Result: True, flip direction
0 + 5 = 5
Great than 718? False, Less than 50? True. Result: True, flip direction
5 - 5 = 0
Great than 718? False, Less than 50? True. Result: True, flip direction

This shows us a useful pattern for identifying the problem. Which is that rectangleY would never reach a value that is greater than 50 but less than 718 with both it’s initial value and the amount of movement given from rectangleDirection

The simplest solution would be to changle rectangleY's initial value to something greater than 50. But you could also adjust rectangleDirection to a value greater than 50 (it wouldn’t look good, though).

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms