Python Forum
Speed issue with sprite update
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Speed issue with sprite update
#9
I thank you for this. I've been spending some time looking at it. Some of it is unfamiliar to me, but I think this is the real trick, right?

 def draw(self, surface, camera, player):
        x_pos = camera.position.x / self.tilesize
        y_pos = camera.position.y / self.tilesize
        x_range = self.get_range(camera.position.x, self.display_size.x, self.map_size[0])
        y_range = self.get_range(camera.position.y, self.display_size.y, self.map_size[1])
        for x, y in product(x_range, y_range):
            try:
                position = int((x - x_pos) * self.tilesize) , int((y - y_pos) * self.tilesize)
                tile = self.map_data[y][x]
                if isinstance(tile, TileLayer):
                    tile.draw(surface, position, self.images, player)
                else:
                    surface.blit(self.images[tile], position)
            except:
                pass
This is the part that save CPU power, no? It looks to me to be the part that finds and draws only the tiles who's coordinates occur on the screen surface. That's the big difference between how I'm currently doing it.
Reply


Messages In This Thread
Speed issue with sprite update - by michael1789 - Feb-17-2020, 12:30 AM
RE: Speed issue with sprite update - by Windspar - Feb-17-2020, 01:55 AM
RE: Speed issue with sprite update - by michael1789 - Feb-17-2020, 03:57 AM
RE: Speed issue with sprite update - by Windspar - Feb-17-2020, 09:31 AM
RE: Speed issue with sprite update - by michael1789 - Feb-19-2020, 05:08 AM
RE: Speed issue with sprite update - by michael1789 - Feb-17-2020, 08:01 PM
RE: Speed issue with sprite update - by Windspar - Feb-19-2020, 11:27 AM
RE: Speed issue with sprite update - by Windspar - Feb-23-2020, 02:46 PM
RE: Speed issue with sprite update - by michael1789 - Feb-27-2020, 03:33 AM
RE: Speed issue with sprite update - by Windspar - Feb-27-2020, 11:25 AM
RE: Speed issue with sprite update - by Windspar - Mar-01-2020, 12:19 PM
RE: Speed issue with sprite update - by michael1789 - Mar-05-2020, 08:39 AM
RE: Speed issue with sprite update - by Windspar - Mar-05-2020, 09:22 AM
RE: Speed issue with sprite update - by michael1789 - Mar-06-2020, 03:06 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] My Pygame Sprite not appearing... noodlespinbot 3 5,015 Oct-30-2020, 06:51 AM
Last Post: robinmurphy
  My Pygame Sprite not appearing... noodlespinbot 1 2,929 Apr-08-2020, 11:25 AM
Last Post: pyzyx3qwerty
  [PyGame] Terrible Sprite controls, need help. michael1789 16 8,398 Dec-18-2019, 10:32 PM
Last Post: michael1789
  [PyGame] Sprite image.get_rect() moves sprite to 0, 0 michael1789 2 5,880 Dec-13-2019, 08:37 PM
Last Post: michael1789
  Pygame sprite not moving michael1789 1 3,986 Nov-10-2019, 03:54 AM
Last Post: michael1789
  Sprite not rendering Clunk_Head 2 3,596 Oct-03-2019, 11:27 AM
Last Post: Clunk_Head
  Need help making a sprite GalaxyCoyote 4 4,409 Aug-11-2019, 09:12 PM
Last Post: metulburr
  creating sprite mask pfaber11 5 5,044 Jun-12-2019, 09:39 PM
Last Post: pfaber11
  [PyGame] assigning rect to sprite pfaber11 1 2,852 May-18-2019, 05:39 PM
Last Post: metulburr
  moving a sprite pfaber11 3 3,392 May-15-2019, 12:52 PM
Last Post: pfaber11

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020