1 Replies - 311 Views - Last Post: 29 June 2013 - 05:41 AM Rate Topic: -----

#1 java_gameDev  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 29-June 13

Rectangle collision next step? help

Posted 29 June 2013 - 03:39 AM

Hi. Can anyone help me on how to push back the rectangles in collision in java?
here is my collision code:
for(int i = 0; i < layer.getHeight() * 32; i ++){
            for(int j = 0; j < layer.getWidth() * 32; j++){
                TiledMapTileLayer.Cell cell = layer.getCell(i,j);
                    if(cell != null){
                        Rectangle rect = new Rectangle();
                        rect.set(i,j,1,1);
                        tiles2.add(rect);
                    }
                }
            }


in the input i set the speed of sprite to zero everytime a collision happens. The problem though is that if I set it to zero the sprite will be stuck in its position so it would always check the collision. I think the solution is to push it back. I've been messing up with my code and i cant figure out how. Any guidance? pls

Is This A Good Question/Topic? 0
  • +

Replies To: Rectangle collision next step? help

#2 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 1
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Rectangle collision next step? help

Posted 29 June 2013 - 05:41 AM

When a collision occurs it needs to be resolved. A collision resolver simply does something after a collision is detected. Your code appears to lack a resolver.

Put some code in there such that when a collision is detected between the rectangles they simply move far apart enough so that a collision is no longer detected. You can refine the actual response of the resolver later.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1