Note that there are some explanatory texts on larger screens.

plurals
  1. POSlick2d | Entity collision detection
    primarykey
    data
    text
    <h2>The problem:</h2> <p>I know this has been asked for many times, but I didnt find any good answers. <br/> So I have got some entities for my game, now what is the best way for checking collisions?</p> <p><strong>Links:</strong></p> <blockquote> <p><a href="https://www.dropbox.com/s/dhvf5vbqj25sgyw/game.jar" rel="nofollow"><strong><em>The game (finished)</em></strong></a><br/></p> </blockquote> <p><strong>Code explanation:</strong> <br/> <em>I've got a list of entities in my world class:</em></p> <pre><code>List&lt;Entity&gt; entities = new ArrayList&lt;Entity&gt;(); // The list in the World class </code></pre> <p><em>I update them with this code (only if inside the view range):</em></p> <pre><code>public void update(GameContainer gc, int delta) { for (int i = 0; i &lt; entities.size(); i++) { entities.get(i).update(gc, delta); } } // Update entities </code></pre> <p><em>So now I wanna check for collision inside the entities update method.</em></p> <p><strong>I tried this as my update method:</strong></p> <pre><code>@Override public void update(GameContainer gc, int delta) { for (Entity entity : world.entities) { if (intersects(entity)) { // world.remove(this); } } } // The update method of an entitiy </code></pre> <p><strong>And this is the current instersects method:</strong></p> <pre><code>public boolean intersects(Entity entity) { if (entity instanceof Player) { // Do nothing } else { if (shape != null) { return this.getShape().intersects(entity.getShape()); } } return false; } // The intersects method of the abstract Entity class </code></pre> <p>Currently the intersects method always returns true. But why?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload