Problem decrementing in Java with '-='

Posted by hanesjw on Stack Overflow See other posts from Stack Overflow or by hanesjw
Published on 2010-06-16T22:27:45Z Indexed on 2010/06/16 22:32 UTC
Read the original article Hit count: 127

Filed under:
|
|

I'm making a scrolling game on Android and am having a hard time figuring out why the code below does not decrement past 0.

Objects start at the end of the screen (so the x position is equal to the width of the screen) the objects move accross the screen by decrementing their x positions. I want them to scroll off of the screen, but when the x position hits 0, the objects just stay at 0, they do not move into the negatives.

Here is my code to move objects on 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 ok if I change

section.x -= incrementor;

to

section.x = section.x - (int)incrementor;

but if i do that the scrolling doesn't appear as smooth.

© Stack Overflow or respective owner

Related posts about java

Related posts about android