I'm following a tutorial for making tiled maps in pygame and on the very first piece of code I'm getting an error. (http://qq.readthedocs.org/en/latest/tiles.html)
On this line "for tile_x in range(0, image_width/width):" it's raising this error: "'float' object cannot be interpreted as an integer". The image dimensions I'm loading are 96x64.
Here's the code, any help would be great.
import pygame, sys
from pygame.locals import *
#load tiles into memory and slice into single tiles
def load_tile_table(filename, width, height):
image = pygame.image.load(filename).convert_alpha()
image_width, image_height = image.get_size()
tile_table = []
for tile_x in range(0, image_width/width):
line = []
tile_table.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 tile_table
def main():
pygame.init()
screen = pygame.display.set_mode((128,98))
while True:
for event in pygame.event.get():
if event.type == QUIT:
sys.exit()
screen.fill((255,255,255))
table = load_tile_table("ground.png", 24, 16)
for x, row in enumerate(table):
for y, tile in enumerate(row):
screen.blit(tile, (x*32, y*24))
pygame.display.update()
main()