本文整理汇总了Python中sprite.Sprite.render方法的典型用法代码示例。如果您正苦于以下问题:Python Sprite.render方法的具体用法?Python Sprite.render怎么用?Python Sprite.render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sprite.Sprite
的用法示例。
在下文中一共展示了Sprite.render方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render
# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import render [as 别名]
def render(self):
glClearStencil(0)
glEnable(GL_STENCIL_TEST)
glStencilFunc(GL_ALWAYS, 1, 255)
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE)
glDisable(GL_DEPTH_TEST)
glColorMask(0,0,0,0)
Sprite.render(self)
glColorMask(1,1,1,1)
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP)
glStencilFunc(GL_EQUAL, 1, 0)
示例2: SpriteEditor
# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import render [as 别名]
#.........这里部分代码省略.........
'title': 'Export as image'}
self.import_options = {'defaultextension': '.jpg',
'filetypes': [('jpeg files', '.jpg'), ('png files', '.png'), ('all files', '.*')],
'initialdir': 'C:\\',
'initialfile': 'default.jpg',
'title': 'Import Browser'}
info_panel = View(540, 0, 295, 520, pygame.Color('0xffffff'))
save_button = Button(5, 375, 65, 20, "Save", self.font)
save_button.on_clicked.connect(self.save_sprite)
load_button = Button(75, 375, 65, 20, "Load", self.font)
load_button.on_clicked.connect(self.load_sprite)
import_button = Button(145, 375, 65, 20, "Import", self.font)
import_button.on_clicked.connect(self.import_sprite)
export_button = Button(215, 375, 65, 20, "Export", self.font)
export_button.on_clicked.connect(self.export_sprite)
self.color_box = ColorPalette(0, 0, 295, 280, self.font)
self.add(info_panel)
info_panel.add(save_button)
info_panel.add(load_button)
info_panel.add(import_button)
info_panel.add(export_button)
info_panel.add(self.color_box)
self.sprite.set_color_box(self.color_box)
self.add(self.sprite)
self.main_loop()
def main_loop(self):
controlled_view = None
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type == pygame.MOUSEBUTTONUP:
mouse_pos = pygame.mouse.get_pos()
hit_view = self.hit(mouse_pos)
hit_view.mouse_up(event.button, mouse_pos)
controlled_view = None
elif event.type == pygame.MOUSEBUTTONDOWN:
mouse_pos = pygame.mouse.get_pos()
hit_view = self.hit(mouse_pos)
controlled_view = hit_view
hit_view.mouse_down(event.button, mouse_pos)
elif event.type == pygame.MOUSEMOTION:
mouse_pos = pygame.mouse.get_pos()
hit_view = self.hit(mouse_pos)
if controlled_view and controlled_view.draggable:
controlled_view.mouse_drag(controlled_view, mouse_pos, event)
else:
hit_view.mouse_drag(controlled_view, mouse_pos, event)
self.flip()
self.fps_clock.tick(120)
def load_sprite(self):
"""Loads a .spr Sprite file as the current_sprite and is used by the Load Button."""
filename = tkFileDialog.askopenfilename(**self.options)
if not filename == '':
self.color_box.reset()
session = shelve.open(filename)
self.sprite.sprite_size = session['dimension']
self.sprite.pixel_size = session['size']
for index in range(len(self.sprite.pixels)):
color, alpha = session['%d' % index]
self.sprite.pixels[index].change_color(color)
self.sprite.pixels[index].set_alpha(alpha)
self.sprite.color_box.add_to_history(color)
session.close()
pygame.event.pump()
def save_sprite(self):
"""Saves the current_sprite as a .spr Sprite file and is used by the Save Button."""
filename = tkFileDialog.asksaveasfilename(**self.options)
if not filename == '':
session = shelve.open(filename)
session['dimension'] = self.sprite.sprite_size()
session['size'] = self.sprite.pixel_size()
for index in range(len(self.sprite.pixels)):
color = self.sprite.pixels[index].get_color()
alpha = self.sprite.pixels[index].get_alpha()
session['%d' % index] = (color, alpha)
session.close()
pygame.event.pump()
def export_sprite(self):
"""Exports the current_sprite as an image and is used by the Export Button."""
filename = tkFileDialog.asksaveasfilename(**self.export_options)
if not filename == '':
pygame.image.save(self.sprite.make_image(), filename)
pygame.event.pump()
def import_sprite(self):
"""Imports an image file to the current_sprite and is used by the Import Button."""
filename = tkFileDialog.askopenfilename(**self.import_options)
if not filename == '':
image = Image.open(filename).resize(self.sprite.sprite_size(), Image.BICUBIC)
self.sprite.image_to_sprite(image)
self.sprite.render(self.window)
pygame.event.pump()
示例3: Ball
# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import render [as 别名]
#.........这里部分代码省略.........
rangle = (self.calculate_angle(colliding_line) - self.gangle) % 360
if 90 < rangle < 135:
self.flagGround = True
self.angle = rangle
self.calculate_rangle()
else:
self.dh = 0
def catch_right_wall(self, colliding_line):
rangle = (self.calculate_angle(colliding_line) - self.gangle)
if 225 < rangle < 270:
self.flagGround = True
self.angle = rangle
self.calculate_rangle()
else:
self.dh = 0
def perform_ground_test(self):
for platform in self.game.platforms:
collision = self.sensor_ground.collide(platform)
if collision is not None:
angle = self.calculate_angle(collision[1])
if angle != self.angle and angle != 90:
return False
return True
self.flagGround = False
self.set_gravity(self.gangle)
return False
def update(self, dt):
self.update_lock_timers(dt)
if self.flagGround:
if not self.keyJump:
self.flagAllowJump = True
else:
# I'd like to have the sensors be invisible when not on the ground.
'''
self.sensor_left_ground.visible = False
self.sensor_middle_ground.visible = False
self.sensor_right_ground.visible = False
'''
self.handle_physics()
self.perform_speed_movement(dt)
if not self.flagGround or not self.perform_ground_test():
self.perform_gravity_movement(dt)
self.calculate_state()
self.calculate_rangle()
def update_lock_timers(self, dt):
if self.hlock > 0:
self.hlock = max(self.hlock - 60 * dt, 0)
if self.hlock == 0:
self.flagAllowHorizMovement = True
def set_hlock(self, frames):
self.hlock = frames
self.flagAllowHorizMovement = False
def draw(self):
self.sprite.render()
def key_press(self, message):
if message == 'up':
self.keyUp = True
elif message == 'down':
self.keyDown = True
elif message == 'left':
self.keyLeft = True
elif message == 'right':
self.keyRight = True
elif message == 'jump':
self.keyJump = True
elif message == 'reset':
self.set_position(100,96)
self.dv = 0
self.dh = 0
self.set_gravity(0.0)
elif message == 'gdown':
self.set_gravity(0.0)
elif message == 'gright':
self.set_gravity(90.0)
elif message == 'gup':
self.set_gravity(180.0)
elif message == 'gleft':
self.set_gravity(270.0)
elif message == 'hlock':
self.set_hlock(30)
def key_release(self, message):
if message == 'up':
self.keyUp = False
elif message == 'down':
self.keyDown = False
elif message == 'left':
self.keyLeft = False
elif message == 'right':
self.keyRight = False
elif message == 'jump':
self.keyJump = False
self.release_jump()
示例4:
# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import render [as 别名]
if not strela.push:
strela.x = hero.x
strela.y = hero.y
strela.push = True
screen.fill((50, 50, 50))
if zet.right:
zet.x -= 1
if zet.x == 0:
zet.right = False
else:
zet.x += 1
if zet.x == 350:
zet.right = True
if strela.y < 0:
strela.push = False
if not strela.push:
strela.y = 350
strela.x = -10
else:
strela.y -= 1
strela.render(screen)
zet.render(screen)
hero.render(screen)
window.blit(screen, (0, 0))
pygame.display.flip()