Pygame: Map Tile or Large Image

I’m trying to decide if it’s better to use a pre-processed large image to scroll through a card game or to display separate fragments on each frame. I tried to program the game in both directions and I do not see an obvious difference in speed, but this may be due to my lack of experience.

Also, is there a speed for memory not to use a pre-rendered map?

+5
source share
4 answers

The only reason I can think about choosing one over the other on modern equipment (something as fast and with the same number of sheep as, say, the iPhone) would be technical, which would make it easier to use the game code . There is not much to distinguish them.

The only exception I can think of is that if you use a really massive background and render fragments in the GPU, the tiles may be textures and you will get a little speed because you don't have to push a lot of data between the processor and gpu per frame, and it will use very little video memory.

+5
source

. , , .

+1

, , .

, , , "".

( convert() - 16 ) .

, , , 150 FPS, , ~ 100? MB RAM

image = image.convert()#video system has to be initialed

(5000 * 5000), - (blit this , ) * 50 , , blit .

def draw(dr,image,count,radius,r):
   for i in range(0,5000,5000//count):
      for j in range(0,5000,5000//count):
         dr.circle(image,(r.randint(0,255),r.randint(0,255),r.randint(0,255)),[i,j],radius,0)

def geschw_test(screen,image,p):
   t1 = p.time.get_ticks()
   screen.blit(image,(-100,-100))
   p.display.flip()
   return p.time.get_ticks() - t1

import pygame as p
import random as r

p.init()
image = p.Surface([5000,5000])
image.fill((255,255,255))
image.set_colorkey((255,255,255))
screen = p.display.set_mode([1440,900],p.SWSURFACE,16)
image = image.convert()#extremely efficient
screen.fill((70,200,70))
draw(p.draw,image,65,50,r)#draw on surface
zahler = 0
anz = 20
speed_arr = []
while zahler < anz:
   zahler += 1
   screen.fill((0,0,0))
   speed_arr.append(geschw_test(screen,image,p))
p.quit()
speed = 0
for i in speed_arr:
   speed += i
print(round(speed/anz,1),"miliseconds per blit with flip")
+1
source

Depending on the size of the map that you want to create, however, using real technology it is very difficult to see that the tiled-out map will take longer than expected, the tile-based games are almost extinguished, however, it’s always good practice and the starting point for game programming world.

0
source

All Articles