Skip to content

Commit

Permalink
Add some spatial hashing fixes from 2.0 branch.
Browse files Browse the repository at this point in the history
  • Loading branch information
pvcraven committed Aug 24, 2018
1 parent 6ba55bc commit bafeb7a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 4 additions & 3 deletions arcade/sprite.py
Expand Up @@ -429,9 +429,9 @@ def _set_center_x(self, new_value: float):
""" Set the center x coordinate of the sprite. """
if new_value != self._position[0]:
self.clear_spatial_hashes()
self._position[0] = new_value
self._point_list_cache = None

self._position[0] = new_value
self.add_spatial_hashes()

center_x = property(_get_center_x, _set_center_x)

Expand All @@ -443,8 +443,9 @@ def _set_center_y(self, new_value: float):
""" Set the center y coordinate of the sprite. """
if new_value != self._position[1]:
self.clear_spatial_hashes()
self._position[1] = new_value
self._point_list_cache = None
self._position[1] = new_value
self.add_spatial_hashes()

center_y = property(_get_center_y, _set_center_y)

Expand Down
5 changes: 4 additions & 1 deletion arcade/sprite_list.py
Expand Up @@ -314,18 +314,21 @@ def append(self, item: T):
self.sprite_list.append(item)
item.register_sprite_list(self)
self.vbo_dirty = True
if self.use_spatial_hash:
self.spatial_hash.insert_object_for_box(item)

def recalculate_spatial_hash(self, item: T):
if self.use_spatial_hash:
self.spatial_hash.remove_object(item)
self.spatial_hash.append_object(item)
self.spatial_hash.insert_object_for_box(item)

def remove(self, item: T):
"""
Remove a specific sprite from the list.
"""
self.sprite_list.remove(item)
self.vbo_dirty = True

if self.use_spatial_hash:
self.spatial_hash.remove_object(item)

Expand Down

0 comments on commit bafeb7a

Please sign in to comment.