Python Forum
[PyGame] Tilemap 3 squares too tall
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Tilemap 3 squares too tall
#1
Hi all,

Very new, learning python for fun.

I've been mostly following this a youtube tutorial by KidsCanCode on youtube for making a tile based game.

Long story short, I have a player centered camera and a scrolling background (just coloured sprite Rects now). It all looks and works like it should except when scrolling down it seems that the map thinks it is 3 squares too tall; as if my "map.txt" has three extra lines to it.

"1"s = a wall tile, "."s = blank tile, on a 32x32 pixel grid. Right, left, top, the camera works fine, but going down there are 3 rows of blank tiles displayed on the outside of my walls, which are the lowest line in the .txt file.

I used "strip" like in the tutorial to remove the spaces at the end of each line, but it did nothing for the extra "phantom" lines.

Changing display window size changes nothing.

Does this sound familiar to someone?

Many thanks,
m.
Reply
#2
you would have to show us the code related to your tilemap
Recommended Tutorials:
Reply
#3
Hopefully this is it:



class Map:
def __init__(self, f):
self.map_data = []
f = open("C:/Users/owner/Desktop/map.txt", "rt")
for line in f:
self.map_data.append(line.strip())

self.tilewidth = len(self.map_data[0])
self.tileheight = len(self.map_data)
self.width = self.tilewidth * TILESIZE
self.height = self.tilewidth * TILESIZE

class Camera:
def __init__(self, width, height):
self.camera = pygame.Rect(0,0, width, height)
self.width = width
self.height = height

def apply(self, entity):
return entity.rect.move(self.camera.topleft)

def update(self, target):
x = -target.rect.x + int(WIDTH / 2)
y = -target.rect.y + int(HEIGHT / 2)

x = min(0, x)
y = min(0, y)
x = max(-(self.width - WIDTH), x)
y = max(-(self.height - HEIGHT), y)

self.camera = pygame.Rect(x, y, self.width, self.height)



ps.... how to i cut&paste from Thonny and keep indents? lol
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Infinite generating tilemap pygame Kolterdyx 2 3,707 Jun-14-2020, 09:22 AM
Last Post: buran

Forum Jump:

User Panel Messages

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