# Rectangle collision next step? help

Page 1 of 1

## 1 Replies - 666 Views - Last Post: 29 June 2013 - 05:41 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=323877&amp;s=1386108458faea2ea1b2b04ee9d994e5&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 java_gameDev

Reputation: 0
• 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);
}
}
}
```

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

• D.I.C Lover

Reputation: 2
• 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.