LibGDX rectangle's y-position updates even after collision -


i'm working 2d platformer , want make box'es fall sky. , when collision between box , ground occur box'es should stop fall. here's code fo collision detection , update in box class

public box(int x, int y){          hitbox = new rectangle(x, y, 64, 64);         bottom = new rectangle(x + 5, y, 54, 14);         top = new rectangle(x + 5, y + 5 + 50, 54, 14);         // other code } @override public void update(float delta) {     if(!hits){         velocity -= (1 * delta);         system.out.println("velc " + velocity);         hitbox.y += velocity;         top.y += velocity;         bottom.y += velocity;         sprite.setposition(hitbox.x, hitbox.y);     } }  @override public int hits2(rectangle r) {     if(bottom.overlaps(r)){         velocity = 0;         hits = true;         system.out.println("hit");         return 1;     }     system.out.println("n");     hits = false;     return 0; } 

and here's code main class

for(int i=0; i<list.size(); i++){             box tmpbox = (box) (list.get(i) instanceof box ? list.get(i) : null);             for(int j=0; j<list.size(); j++){                 if(tmpbox != null){                     brick brick = (brick) (list.get(j) instanceof brick ? list.get(j) : null);                     box tmpotherbox = (box) (list.get(j) instanceof box ? list.get(j) : null);                     if(brick != null){ // if collision ground rectangle                         tmpbox.hits2(brick.gettop());                     }                     if(tmpotherbox != null && tmpotherbox.hashcode() != tmpbox.hashcode()){ if collision other box rectangle                         tmpbox.hits2(tmpotherbox.gethitbox());                     }                 }             }             if(tmpbox != null){                 tmpbox.update(gdx.graphics.getdeltatime());             } } 

but problem when box collides ground box still fall down except velocity small. why strange result? know remove hits = false; in hits2 method , box won't fall down when collides ground, still why collision between rectangles work strange? update: here how looks visually

have checked collision rectangle of ground drawing it? , draw collision of box , check collision point. because had done in 1 of game, , drawing ground rectangle collision @ bottom when actor going out of screen think way collides.

collision in libgdx works overlap method.


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -