donderdag 7 april 2011

Rectangle Collision Example

This is a simple example that shows you how to check for collision between 2 rectangles.

import java.awt.*;
import java.applet.*;

public class RectangleCollision extends Applet {
 public void init() {
 public void paint(Graphics g) {
  Rectangle rec1 = new Rectangle(10,10,20,20);
  Rectangle rec2 = new Rectangle(15,15,20,20);
  g.drawString("Filled Rectangle Collision", 50, 60 );

This type of collision is mostly used. I think it is faster for the cpu then the polygon and area collision but I have no idea how much faster.

You can copy and paste the example, it should work directly.

Geen opmerkingen:

Een reactie posten