Ok so i feel like I should know how to do this but heres my problem: I am increasing the X cordinates of an image by writing

1 2 3 4

floataX = 50;while(aX < 100){aX += .01; }

Normally this would work for me (im not sure if its the right way to do it but thats how I do it) but my computer is processing this so quickly that I cant notice the change in movement, I just notice the image at the final value. As i decrease the the amount that aX is increased by the same thing still happens until the game crashes... what should i do?

This is why the image will always be drawn at the same coordinates (x=100). Instead of using while loops within your game loop, you would simply increment the X position by a slight amount each frame. So your code changes to this:

1 2 3 4

floatx;

... inframe ...x += 0.5f;

You might want to multiply it by the delta time for framerate-independent movement:

This is how I learn. You may not like it but I learn best with examples and trying things not just being taught something...Sorry lol

If you aren't already, please use an IDE - I highly recommend IntelliJ IDEA, but eclipse will work too. If something isn't working right, you need to put a breakpoint in your code, then step through it line by line. That will usually give you insight onto why X is happening. As you gain more experience, you start gaining the ability to simply read the code and run it through your mind's debugger, which is never 100% accurate, but still works pretty well

thanks this really helped understand. if i wasnt making a game is there really a reason to use a while statement over an if?

Instructions in a program are usually executed sequentially, one by one. A while loop is a loop. That means after the last instruction the processor jumps back to the start.sowhile(a < 100) {do something}meansif(a >= 100) jump over the next 2 linesdo somethingjump back by two lines

This is how I learn. You may not like it but I learn best with examples and trying things not just being taught something...Sorry lol

If you are learning new algorithm or mechanism like A*, dungeon generator, etc then yes. But you better at least can imagine how basic procedure like IF, WHILE, SWITCH, FOR running and the result in your head. It's the best debugger tool.

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