【问题标题】:argument 2 to map() must support iterationmap() 的参数 2 必须支持迭代
【发布时间】:2015-06-01 17:48:54
【问题描述】:

嗨,我正在制作一个基本的光线投射引擎,所以我认为从小地图开始会很好,但问题是我的类地图在构造函数中要求一个 mapGrid,当我通过它时,python 给了我这个错误@ 987654321@

这是代码: 主要部分

import pygame
def map(object):
    def __init__(self,grid,scale):
        self.grid= grid
        self.mapWidth= len(grid[0]) #Number of map blocks
        self.mapHeight= len(grid) 
        self.miniMapScale= scale #How many pixels to draw a map block
        self.miniWidth= self.mapWidth * self.miniMapScale #Size of the minimap
        self.miniHeight= self.mapHeight * self.miniMapScale

        self.rectGrid= grid

        for y in range(self.mapHeight):
            for x in range(self.mapWidth):
                self.rectGrid[y][x]= pygame.Rect(x,y,self.miniWidth,self.miniHeight)

    def blitMiniMap():
        pass

数据文件

mapGrid= [
    [1,1,1,1],
    [1,0,0,1],
    [1,0,0,1],
    [1,1,1,1]
]

size = [640, 480]

地图类

import pygame
def map(object):
    def __init__(self,grid,scale):
        self.grid= grid
        self.mapWidth= len(grid[0]) #Number of map blocks
        self.mapHeight= len(grid) 
        self.miniMapScale= scale #How many pixels to draw a map block
        self.miniWidth= self.mapWidth * self.miniMapScale #Size of the minimap
        self.miniHeight= self.mapHeight * self.miniMapScale

        self.rectGrid= grid

        for y in range(self.mapHeight):
            for x in range(self.mapWidth):
                self.rectGrid[y][x]= pygame.Rect(x,y,self.miniWidth,self.miniHeight)

    def blitMiniMap():
        pass 

谢谢。

【问题讨论】:

  • 你确定你必须两次发布相同的代码吗?有一个名为 map 的内置函数,it 有两个参数要传递给它

标签: python list arguments pygame iteration


【解决方案1】:

map是一个python内置函数。使用 map 作为函数名称会导致混淆,因此您应该考虑将 map 函数重命名为不同的名称。

另外,你所说的“地图类”只定义了一个函数,而不是一个类。您是否在类定义中将defclass 混淆了?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-14
    • 2012-12-12
    • 2016-03-11
    • 1970-01-01
    • 2020-10-27
    相关资源
    最近更新 更多