PyGame 与 Tile 渲染地图发生碰撞?
我的图块渲染器遇到问题,它会遍历文本文件并查找字符,然后将它们转换为矩形。我的问题是,只有最近的图块/矩形才会被计算为碰撞。
我的问题的视频: http://youtu.be/7wAHp-vgrLU
我的代码工作原理如下:
wall = pygame.draw.rect(screen, (40,40,40), (current_tile_x,current_tile_y,tile_size,tile_size), 0)
if wall.colliderect(collision) == 1:
print "Collision!"
玩家的矩形被定义为碰撞。我认为的问题是,对于每块墙砖,var 墙都会被覆盖,那么我将如何解决这个问题呢?
I'm having problems with my tile renderer, which goes through a text file and finds characters, converting them into rects. My problem is that only the most recent tile / rect is counted for collisions.
A video of my problem: http://youtu.be/7wAHp-vgrLU
My code works like this:
wall = pygame.draw.rect(screen, (40,40,40), (current_tile_x,current_tile_y,tile_size,tile_size), 0)
if wall.colliderect(collision) == 1:
print "Collision!"
The player's rect is defined as collision. The problem I think is that for every wall tile, the var wall gets overwritten, so how would I go about fixing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您刚刚回答自己,您应该使用所有要测试的矩形进行迭代:
You just answered yourself, you should make a iterable with all rects to be tested: