本文整理匯總了Python中sdl2.ext方法的典型用法代碼示例。如果您正苦於以下問題:Python sdl2.ext方法的具體用法?Python sdl2.ext怎麽用?Python sdl2.ext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sdl2
的用法示例。
在下文中一共展示了sdl2.ext方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import ext [as 別名]
def __init__(self, model):
self.model = model
sdlttf.TTF_Init()
self.window = sdl2.ext.Window("PyTGM Alpha", size=self.windowsize)
self.renderer = sdl2.ext.SoftwareSpriteRenderSystem(self.window)
self.sfactory = sdl2.ext.SpriteFactory(sdl2.ext.SOFTWARE)
self.tspr = self.sfactory.from_color(0x00000000, size=(350, 650),
masks=(0xff000000,0x00ff0000,0x0000ff00,0x000000ff))
self.trds = sdl2.ext.Renderer(self.tspr)
self.trds.blendmode = sdl2.SDL_BLENDMODE_BLEND
self.tfactory = sdl2.ext.SpriteFactory(sdl2.ext.TEXTURE, renderer = self.trds)
self.trds.color = sdl2.ext.Color(255,255,255,0)
self.trds.clear()
self.loadtexture()
self.window.show()
self.render = self.draw()
示例2: orb_turn
# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import ext [as 別名]
def orb_turn(self, activity):
events = sdl2.ext.get_events()
if events:
activity.mark(
l=self,
s='sdl2 event(s)')
for event in events:
if event.type == sdl2.SDL_QUIT:
raise SolentQuitException()
elif event.type == sdl2.SDL_KEYDOWN:
if event.key.keysym.sym == sdl2.SDLK_UP:
self.ent_player_b.velocity.vy = -3
elif event.key.keysym.sym == sdl2.SDLK_DOWN:
self.ent_player_b.velocity.vy = 3
elif event.key.keysym.sym == ord('\\'):
raise SolentQuitException()
elif event.type == sdl2.SDL_KEYUP:
if event.key.keysym.sym in (sdl2.SDLK_UP, sdl2.SDLK_DOWN):
self.ent_player_b.velocity.vy = 0
self.sdl_world.process()
示例3: draw_lines
# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import ext [as 別名]
def draw_lines(surface, width, height):
# Fill the whole surface with a black color.
sdl2.ext.fill(surface, 0)
for x in range(15):
# Create a set of four random points for drawing the line.
x1, x2 = randint(0, width), randint(0, width)
y1, y2 = randint(0, height), randint(0, height)
# Create a random color.
color = sdl2.ext.Color(randint(0, 255),
randint(0, 255),
randint(0, 255))
# Draw the line with the specified color on the surface.
# We also could create a set of points to be passed to the function
# in the form
#
# line(surface, color, (x1, y1, x2, y2, x3, y3, x4, y4, ...))
# ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^
# first line second line
sdl2.ext.line(surface, color, (x1, y1, x2, y2))
# Draws random, filled rectangles on the passed surface
示例4: draw_rects
# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import ext [as 別名]
def draw_rects(surface, width, height):
# Fill the whole surface with a black color.
sdl2.ext.fill(surface, 0)
for k in range(15):
# Create a set of four random points for the edges of the rectangle.
x, y = randint(0, width), randint(0, height)
w, h = randint(1, width // 2), randint(1, height // 2)
# Create a random color.
color = sdl2.ext.Color(randint(0, 255),
randint(0, 255),
randint(0, 255))
# Draw the filled rect with the specified color on the surface.
# We also could create a set of points to be passed to the function
# in the form
#
# fill(surface, color, ((x1, y1, x2, y2), (x3, y3, x4, y4), ...))
# ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^
# first rect second rect
sdl2.ext.fill(surface, color, (x, y, w, h))
示例5: oncheck
# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import ext [as 別名]
def oncheck(button, event):
if button.checked:
color = GREEN
else:
color = RED
if button.factory.sprite_type == sdl2.ext.SOFTWARE:
sdl2.ext.fill(button.surface, color)
else:
# SDL textures do not support color manipulation operation as easy
# as software surface (since the texture is ideally stored somwhere
# on the GPU memory in a GPU-specific layout [or not]). To circumvent
# this, we create a temporary sprite (texture) and exchange the button
# texture with it.
tmpsprite = button.factory.from_color(color, button.size)
button.texture, tmpsprite.texture = tmpsprite.texture, button.texture
del tmpsprite
示例6: handle_events
# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import ext [as 別名]
def handle_events():
global CLICKEDBUTTON
for event in sdl2.ext.get_events():
if event.type == sdl2.SDL_QUIT:
shutdown()
elif event.type == sdl2.SDL_MOUSEBUTTONUP:
mousex, mousey = event.button.x, event.button.y
button = getButtonClicked(mousex, mousey)
if button:
CLICKEDBUTTON.append(button)
elif event.type == sdl2.SDL_KEYDOWN:
sym = event.key.keysym.sym
if sym == sdl2.SDLK_ESCAPE:
shutdown()
elif sym == sdl2.SDLK_q:
CLICKEDBUTTON.append(YELLOW)
elif sym == sdl2.SDLK_w:
CLICKEDBUTTON.append(BLUE)
elif sym == sdl2.SDLK_a:
CLICKEDBUTTON.append(RED)
elif sym == sdl2.SDLK_s:
CLICKEDBUTTON.append(GREEN)
示例7: main
# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import ext [as 別名]
def main():
#cause I don't want to pass these around
global WINDOW, REN, SPRITE_FACTORY, SPRITE_RENDERER
sdl2.ext.init()
WINDOW = sdl2.ext.Window("Wormy", size=(WINDOWWIDTH, WINDOWHEIGHT))
REN = sdl2.ext.Renderer(WINDOW, flags=sdl2.SDL_RENDERER_SOFTWARE)
WINDOW.show()
font_file = sysfont.get_font("freesans", sysfont.STYLE_BOLD)
font_manager = sdl2.ext.FontManager(font_file, size=18)
#fontmanager=font_manager will be default_args passed to every sprite creation method
SPRITE_FACTORY = sdl2.ext.SpriteFactory(sdl2.ext.SOFTWARE, renderer=REN, fontmanager=font_manager, free=True)
SPRITE_RENDERER = SPRITE_FACTORY.create_sprite_render_system(WINDOW)
showStartScreen()
while True:
runGame()
showGameOverScreen()
示例8: get_events
# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import ext [as 別名]
def get_events(self):
for sdl_event in sdl2.ext.get_events():
yield to_vulk_event(sdl_event)
示例9: __init__
# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import ext [as 別名]
def __init__(self):
sdl2.ext.init()
self.model = model.Model('', time.time())
self.view = view.View(self.model)
self.audio = audio.Audio(self.model)
self.framerate = 60;
示例10: draw
# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import ext [as 別名]
def draw(self):
stacksprite = self.tspr.subsprite((0, 0, 240, 504))
stacksprite.x, stacksprite.y = self.origin
cpiecesprite = self.tspr.subsprite((240, 0, 96, 96))
nextsprite = self.tspr.subsprite((0,504,288,96))
nextsprite.x, nextsprite.y = 120,36
tick = 0
cp = ['',-1]
while True:
yield
tick += 1
if cp[0] != [self.model.next[0], self.model.piecepos[2]]:
self.trds.clear()
self.drawstack()
self.drawnext()
self.drawcpiece()
self.drawlevel()
cp = [self.model.next[0], self.model.piecepos[2]]
cpiecesprite.y, cpiecesprite.x = \
(20-self.model.piecepos[0])*self.tsize+self.origin[1], \
self.model.piecepos[1]*self.tsize+self.origin[0]
self.drawtime(tick)
sdl2.ext.fill(self.renderer.surface, sdl2.ext.Color(0,0,0))
self.renderer.render([stacksprite, nextsprite, self.border, self.timertex,
self.leveltex, cpiecesprite])
self.window.refresh()
示例11: render
# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import ext [as 別名]
def render(self, components):
sdl2.ext.fill(self.surface, sdl2.ext.Color(0, 0, 0))
super(SoftwareRenderer, self).render(components)
示例12: __init__
# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import ext [as 別名]
def __init__(self, minx, miny, maxx, maxy):
super(MovementSystem, self).__init__()
self.componenttypes = Velocity, sdl2.ext.Sprite
self.minx = minx
self.miny = miny
self.maxx = maxx
self.maxy = maxy
示例13: orb_close
# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import ext [as 別名]
def orb_close(self):
sdl2.ext.quit()
#
示例14: render
# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import ext [as 別名]
def render(self, components):
sdl2.ext.fill(self.surface, sdl2.ext.Color(255,255,255))
# self.grid.plot(self.surface)
for l in self.lines:
l.plot(self.surface, self.grid)
super(Renderer, self).render(components)
示例15: __init__
# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import ext [as 別名]
def __init__(self, title="Fractal App"):
sdl2.ext.init()
self.window = sdl2.ext.Window(title, size=(800, 600))
self.world = sdl2.ext.World()
self.renderer = Renderer(self.window)
self.world.add_system(self.renderer)