I'm making a scrolling game on Android, and it's hard for me to understand why the code below does not decrease to 0.
Objects start at the end of the screen (so that the x position is equal to the width of the screen) objects move around the screen, decreasing their x position. I want them to scroll from the screen, but when the x position reaches 0, the objects just stay at 0, they don't move to negatives.
Here is my code for moving objects to the screen
private void incrementPositions(long delta) { float incrementor = (delta / 1000F) * Globals.MAP_SECTION_SPEED; for(Map.Entry<Integer, HashMap<Integer, MapSection>> column : scrollingMap.entrySet()) { for(Map.Entry<Integer, MapSection> row : column.getValue().entrySet()) { MapSection section = row.getValue(); section.x -= incrementor; } } }
It works fine if I change
section.x -= incrementor;
to
section.x = section.x - (int)incrementor;
but if I do this, the scroll does not look smooth.
java android
hanesjw
source share