本文整理汇总了Python中Convert.pixel_to_world方法的典型用法代码示例。如果您正苦于以下问题:Python Convert.pixel_to_world方法的具体用法?Python Convert.pixel_to_world怎么用?Python Convert.pixel_to_world使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Convert
的用法示例。
在下文中一共展示了Convert.pixel_to_world方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import Convert [as 别名]
# 或者: from Convert import pixel_to_world [as 别名]
def __init__(self, pos, imageurl, scale=()):
self.pos = pos
self.imageurl = imageurl
self.scale = scale
self.load_image()
#bounding box is in pixels because it can only have ints
self.bounding_box = pygame.Rect(Convert.world_to_pixel(pos[0]), Convert.world_to_pixel(pos[1]), self.img.get_width(), self.img.get_height())
self.width = Convert.pixel_to_world(self.img.get_width()) + 1
self.height = Convert.pixel_to_world(self.img.get_height()) + 1
self.dir = [0, 0] #direction: -1, 0, 1
self.vel = [0, 0] #speeds: any numbers
示例2: render_blocks
# 需要导入模块: import Convert [as 别名]
# 或者: from Convert import pixel_to_world [as 别名]
def render_blocks(self, screen, viewport, background):
top = max(Convert.pixel_to_world(viewport.y), 0)
bottom = min(Convert.pixel_to_world(viewport.y + viewport.height) + 1, World.HEIGHT - 1)
for blocky in range(top, bottom):
leftData = Convert.pixel_to_chunk(viewport.x)
rightData = Convert.pixel_to_chunk(viewport.x + viewport.width)
if leftData[1] == self.x:
for blockx in range(leftData[0], WIDTH):
self.render_block(blockx, blocky, screen, viewport, background)
elif leftData[1] < self.x < rightData[1]:
for blockx in range(WIDTH):
self.render_block(blockx, blocky, screen, viewport, background)
elif self.x == rightData[1]:
for blockx in range(0, rightData[0] + 1):
self.render_block(blockx, blocky, screen, viewport, background)
示例3: render
# 需要导入模块: import Convert [as 别名]
# 或者: from Convert import pixel_to_world [as 别名]
def render(self, screen, viewport):
top = max(Convert.pixel_to_world(viewport.y), 0)
bottom = min(Convert.pixel_to_world(viewport.y + viewport.height) + 1, World.HEIGHT)
for blocky in range(top, bottom):
leftData = Convert.pixel_to_chunk(viewport.x)
rightData = Convert.pixel_to_chunk(viewport.x + viewport.width)
if leftData[1] == self.x:
for blockx in range(leftData[0], WIDTH):
self.render_block(self.blocks[blocky][blockx], (blockx, blocky), screen, viewport)
elif leftData[1] < self.x < rightData[1]:
for blockx in range(WIDTH):
self.render_block(self.blocks[blocky][blockx], (blockx, blocky), screen, viewport)
elif self.x == rightData[1]:
for blockx in range(0, rightData[0] + 1):
self.render_block(self.blocks[blocky][blockx], (blockx, blocky), screen, viewport)
for entity in self.entities:
entity.render(screen, Convert.world_to_viewport(entity.pos, viewport))