How to decrease processing on the moon? or Muti hash?

Asked

Viewed 66 times

1

I have a table with several 5 position Tables where the first two are the position in a Cartesian plane.

    --Table with water collors
colors = {{r=15,g=94,b=156},{r=35,g=137,b=218},{r=28,g=163,b=236},{r=90,g=188,b=216},{r=116,g=204,b=244}}
points = {}
for i=1,10000 do
    j = love.math.random(1,table.getn(colors)-1)
    table.insert(points,{i,i,colors[j].r,colors[j].g,colors[j].b})

I’m making a method to change the position (the first two positions of the vector) of this object, but for this I need to know if there are any objects on top of each other, ie if the first two values of the table coincide with the value of another table, I’m assuming that comparing one by one is unviable,?

  • LÖVE contains collision detection functions: https://love2d.org/wiki/love.physics

  • @lhf normally the Löve2d physics library is not the best option because it is very confusing and has few examples. In fact most of her objects don’t even have an example of how to use, I had to study implementations of Box2d in other languages to get an idea of how to use.

1 answer

0

The physics collision detection is very laborious and the Löve2d documentation recommends only using this if you are sure what you want to do needs physics (like a pinball game I did once).

A simple trick you can do is the following:

  1. Divide your screen into 4 quadrants, each with a table of objects that are in that quadrant
  2. Control the placement of objects by changing them from table when they change quadrant
  3. For a particular object you know which quadrant to check if it collides with the others of that quadrant by checking the four how many of the edge rectangle (bounding box)

This way is very simple to implement and should offer the performance you seek. Otherwise there is still another library in Löve2d called Bump that allows checking collision, it is simpler than physics and indicated to make a character walk on a platform for example, but it is much more complicated to use than this strategy here.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.