Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7767039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:34:35+00:00 2026-06-01T15:34:35+00:00

I have small library i want to use for creating games. First, i tried

  • 0

I have small library i want to use for creating games. First, i tried to implement pixel perfect collision detection, but that did not went well, so i decided to use simple bounding box collision detection. It works fine, but after amount of objects exceeds around 20, it starts slowing down. Here is my code:
(Runs in loop, 25 times per second)

for (int i=0;i<sc.collGr.size();i++){
    CollisionGroup gr=sc.collGr.get(i);
    Collidable[] cc=gr.getCollidables();
    for (int l=0;l<cc.length;l++){
        for (int w=l+1;w<cc.length;w++){
            if (BorderBox.areColliding(cc[l].getBorderBox(), cc[w].getBorderBox()){
                addEventToHandler(sc.collGr.get(i),cc[l],cc[w]);
            }
        }
   }
}

part of BorderBox class:

public class BorderBox {
int top;
int down;
int left;
int right;

/**
 * Creates new BorderBox object
 * Arguments: (top, down, left, right);
 * */
public BorderBox(int topy,int downy, int leftx,int rightx){
    top=topy;
    down=downy;
    left=leftx;
    right=rightx;
}

/**
 * Checks if two provided BorderBoxes are colliding.
 * */
public static boolean areColliding(BorderBox a,BorderBox b){
    if (b.left<=a.right && b.right>=a.left && b.down>=a.top && b.top<=a.down){
        return true;
    }
    return false;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:34:36+00:00Added an answer on June 1, 2026 at 3:34 pm

    Checking this way is an O(n^2) operation. That is, as you add a new objects, the amount of work you are doing grows quadratic-ally.

    The way I have mitigated this before, along with the other suggestions, is to have two types of collidable objects in two different arrays. One array has a small number of objects, primarily the character, and the other array has enemies. The idea is that you don’t care about enemies colliding with each-other. Thus you dramatically cut down on the amount of work you have to do, by only checking if elements from the smaller array collide with elements in the larger one.

    This is of course game specific, and cannot work if everything has to collide with everything else. Although, I find that is often not the case with simple games.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a static library, libsqlite3.a, that i want to link to my small
I've created a small pixel-font that I want to use in a Flash game.
I'm wondering about the merits of creating a small library, probably for personal use
I want to implement a utility for myself that should provide a small console
I am working on a project where I want to use a C++ library
I have a library whose functionality I want to eventually expose to .NET. The
I have a small project that I want to deploy to both Heroku and
I have two versions of a dependence java library in a small part of
I have the code below, if i don't use watermark it's fine but when
I have this small code library that I'm considering releasing into Open Source. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.