Note that there are some explanatory texts on larger screens.

plurals
  1. POPygame: How to tile subsurfaces on an image
    primarykey
    data
    text
    <p>I'm completely new to Python/Pygame and I'm trying to slice an image up into subsurfaces and then blit them in order to the screen (so that later on I can modify it to call upon a certain tile and then blit it).</p> <p>E1: I think I've finally managed to slice it the right way but there's a little hitch with the blitting.<br> E2: Updated the code and error (been getting this one on most of the code I tried before as well).</p> <pre><code>import pygame from pygame.locals import * pygame.init() screen = pygame.display.set_mode((640, 480)) screen.fill((255, 255, 255)) def load_tileset(filename, width, height): image = pygame.image.load(filename).convert() image_width, image_height = image.get_size() tileset = [] for tile_x in range(0, image_width//width): line = [] tileset.append(line) for tile_y in range(0, image_height//height): rect = (tile_x*width, tile_y*height, width, height) line.append(image.subsurface(rect)) return tileset def draw_background(screen, tile_img, field_rect): img_rect = tile_img.get_rect() for y in range(0,400,32): for x in range(0,600,32): screen.blit(tile_img, (x,y)) Field_Rect = Rect(50,50, 300,300) tileset = load_tileset("platform1.bmp", 17, 17) bg_tile_img = tileset[0] draw_background(screen, bg_tile_img, Field_Rect) while True: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() if event.type == KEYDOWN: if event.key == K_ESCAPE: pygame.quit() pygame.display.flip() </code></pre> <p>The error it gives atm is:<br> img_rect = tile_img.get_rect()<br> AttributeError: 'list' object has no attribute 'get_rect'</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.
 

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