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

  • Home
  • SEARCH
  • 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 7015401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:38:51+00:00 2026-05-27T22:38:51+00:00

I need help/advice for improving/commenting my current design please :) This relates to collision

  • 0

I need help/advice for improving/commenting my current design please 🙂

This relates to collision detection in a simple game: Dynamic bodies (moving ones) might collide with static bodies (i.e. ground, walls). I’m porting my Obj-C model to Javascript and am facing memory/performance questions as to my way of implementing this.

I’m using a very basic approach: An array of arrays represents my level in terms of physic opacity.

  • bit set to 0: Transparent area, bodies can go through

  • bit set to 1: Opaque area, bodies collide

Testing the transparency/opacity of a pixel simply goes as follows:

if (grid[x][y]) {
 // collide!
}

My knowledge of JS is pretty limited in termes of performance/memory and can’t evaluate how good this approach is 🙂 No idea of the efficiency of using arrays that being said.

Just imagine a 1000-pixel wide level that’s 600px high. It’s a small level but this already means an array containing 1000 arrays each containing up to 600 entries. Besides, I’ve not found a way to ensure I create a 1bit-sized element like low-level languages have.

Using the following, can I be sure an entry isn’t something “else” than a bit?

grid[x][y] = true;
grid[x][y] = false;

Thanks for your time and comments/advices!

J.

  • 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-05-27T22:38:51+00:00Added an answer on May 27, 2026 at 10:38 pm

    If you have an 1000×600 grid, you can guarantee you have at least 601 arrays in memory (1001 if you do it the other way round).

    Rather than doing this, I would consider using either 1 array, or (preferrably) one object with a mapping scheme.

    var map = {};
    map["1x1"] = 1;
    map["1x3"] = 1;
    // assume no-hits are empty and free to move through
    
    function canGoIn(x, y) {
        return map.hasOwnProperty(x + "x" + y);
    };
    

    Alternately;

    var map = [];
    var width = 600;
    map.push(0);
    map.push(1);
    // etc
    
    function canGoIn(x, y) {
        return map[(x * width) + y] == 1;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some advice/help on this, I can't see the wood from the trees
Need help writing a script downloads data from google insight using c# this is
I need help on this following aspx code aspx Code: <asp:Label ID =lblName runat
I need help with this route map routes.MapRoute(Blog_Archive, Blog/Archive/{year}/{month}/{day}, new { controller = Blog,
I need help getting my head around the difference between my current OOP notion
i need help with disk_total_space function.. i have this on my code <?php $sql=select
I need help with my WebView...I put this code in my viewDidLoad and it
I need help in this matter: We have a template of Excel file in
I need help / advice on the below scenario. We are planning to develop
I need some help wrapping my head around this. I am trying to develop

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.