本文整理汇总了Python中sdl2.SDL_Delay方法的典型用法代码示例。如果您正苦于以下问题:Python sdl2.SDL_Delay方法的具体用法?Python sdl2.SDL_Delay怎么用?Python sdl2.SDL_Delay使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sdl2
的用法示例。
在下文中一共展示了sdl2.SDL_Delay方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import sdl2 [as 别名]
# 或者: from sdl2 import SDL_Delay [as 别名]
def __init__(self, cog_h, orb, engine):
self.cog_h = cog_h
self.orb = orb
self.engine = engine
#
self.sdl_world = None
self.sdl_window = None
#
# These need to be kept as class vars, or else they'll
# get deallocated and our app will get crashy.
self.ent_player_a = None
self.ent_player_b = None
self.ent_player_c = None
self.ent_ball = None
#
sdl2.ext.init()
sdl2.SDL_Delay(10)
示例2: _loopForEvents
# 需要导入模块: import sdl2 [as 别名]
# 或者: from sdl2 import SDL_Delay [as 别名]
def _loopForEvents(self):
event = sdl2.SDL_Event()
sdl2.SDL_StartTextInput()
while self.is_running:
# Look at the event queue
while sdl2.SDL_PollEvent(ctypes.byref(event)) != 0:
self.onEvent(event)
# Look for layout changes
if self.need_update:
# Rebuilt only what is needed
for i in self.indices_to_be_built:
self.buildElement(i)
self.indices_to_be_built = []
# Draw the elements
self._refresh()
self.need_update = False
sdl2.SDL_Delay(1)
示例3: test_surface_drawing
# 需要导入模块: import sdl2 [as 别名]
# 或者: from sdl2 import SDL_Delay [as 别名]
def test_surface_drawing():
win_surf = window.get_surface()
test1 = sprite_factory.from_text("A text sprite")
degrees = 0
while degrees < 180:
ren.clear() #fill?
rot = sdlgfx.rotozoomSurface(test1.surface, degrees, 3, sdlgfx.SMOOTHING_ON)
#same lame copy necessary as below
tmp = rot.contents
pos = WIDTH//2 - tmp.w//2, HEIGHT//2 -tmp.h//2
sdl2.SDL_BlitSurface(rot, None, win_surf, sdl2.rect.SDL_Rect(pos[0], pos[1], 0, 0))
degrees += 1
sdl2.SDL_Delay(1000//90)
window.refresh() #equ to sdl2.SDL_UpdateWindowSurface(window.window) ...?
示例4: showGameOverScreen
# 需要导入模块: import sdl2 [as 别名]
# 或者: from sdl2 import SDL_Delay [as 别名]
def showGameOverScreen():
gamesprite = SPRITE_FACTORY.from_text("Game", size=150)
oversprite = SPRITE_FACTORY.from_text("Over", size=150)
pressKey = SPRITE_FACTORY.from_text("Press a key to play.", color=DARKGRAY)
gamesprite.position = WINDOWWIDTH//2 - gamesprite.size[0]//2, 10
oversprite.position = WINDOWWIDTH//2 - oversprite.size[0]//2, gamesprite.size[1] + 35
pressKey.position = WINDOWWIDTH - 200, WINDOWHEIGHT - 30
SPRITE_RENDERER.render((gamesprite, oversprite, pressKey))
REN.present()
sdl2.SDL_Delay(500)
check_for_key_press() # clear out any key presses in the event queue
while True:
if check_for_key_press():
return
#return true if there's been a keypress
示例5: run
# 需要导入模块: import sdl2 [as 别名]
# 或者: from sdl2 import SDL_Delay [as 别名]
def run():
sdl2.SDL_Init(sdl2.SDL_INIT_VIDEO)
window = sdl2.SDL_CreateWindow(b"Hello World",
sdl2.SDL_WINDOWPOS_CENTERED,
sdl2.SDL_WINDOWPOS_CENTERED,
592, 460, sdl2.SDL_WINDOW_SHOWN)
fname = os.path.join(os.path.dirname(os.path.abspath(__file__)),
"resources", "hello.bmp")
image = sdl2.SDL_LoadBMP(fname.encode("utf-8"))
windowsurface = sdl2.SDL_GetWindowSurface(window)
sdl2.SDL_BlitSurface(image, None, windowsurface, None)
sdl2.SDL_UpdateWindowSurface(window)
sdl2.SDL_FreeSurface(image)
running = True
event = sdl2.SDL_Event()
while running:
while sdl2.SDL_PollEvent(ctypes.byref(event)) != 0:
if event.type == sdl2.SDL_QUIT:
running = False
break
sdl2.SDL_Delay(10)
sdl2.SDL_DestroyWindow(window)
sdl2.SDL_Quit()
return 0
示例6: test_surface_sprites
# 需要导入模块: import sdl2 [as 别名]
# 或者: from sdl2 import SDL_Delay [as 别名]
def test_surface_sprites():
test1 = sprite_factory.from_text("A text sprite")
degrees = 0
while degrees < 360:
if get_events([sdl2.SDL_QUIT]):
shutdown()
keylen = ctypes.c_int(10)
print(keylen.value)
keyboard_status = sdl2.SDL_GetKeyboardState(ctypes.byref(keylen))
print(type(keyboard_status))
print(keylen.value)
if keyboard_status[sdl2.SDL_SCANCODE_D]:
print("d is down")
ren.clear() #fill?
rot = sdlgfx.rotozoomSurface(test1.surface, degrees, 3, sdlgfx.SMOOTHING_ON)
#print(type(rot), type(rot.contents))
#<class 'sdl2.surface.LP_SDL_Surface'> <class 'sdl2.surface.SDL_Surface'>
#this is lame ... from_surface takes sdl2.surface.SDL_Surface which means calling contents
#which creates a copy
#Note that ctypes does not have OOR (original object return), it constructs a new, equivalent object each time you retrieve an attribute
#so rot.contents creates a new ~52 byte surface
rot = sprite_factory.from_surface(rot.contents)
rot.position = WIDTH//2 - rot.size[0]//2, HEIGHT//2 -rot.size[1]//2
degrees += 1
sdl2.SDL_Delay(1000//90)
sprite_renderer.render(rot)
ren.present()
#change types to OR'd flags? would mean I don't have to wrap a single
#type in []
示例7: main
# 需要导入模块: import sdl2 [as 别名]
# 或者: from sdl2 import SDL_Delay [as 别名]
def main():
global ren, window, sprite_factory, sprite_renderer
sdl2.ext.init()
window = sdl2.ext.Window("testing", size=(WIDTH, HEIGHT))
window.show()
ren = sdl2.ext.Renderer(window, flags=sdl2.SDL_RENDERER_SOFTWARE)
font_file = sysfont.get_font("freesans")
print(font_file)
font_manager = sdl2.ext.FontManager(font_file, size=24)
#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)
#test1(1000)
#test_surface_drawing()
#sdl2.SDL_Delay(1000)
#test_surface_sprites()
ren.present()
while True:
for event in get_events():
if event.type == sdl2.SDL_QUIT:
shutdown()
elif event.type == sdl2.SDL_MOUSEBUTTONUP:
mousex, mousey = event.button.x, event.button.y
elif event.type == sdl2.SDL_KEYDOWN:
sym = event.key.keysym.sym
if sym == sdl2.SDLK_ESCAPE:
shutdown()
test_surface_sprites()
示例8: flashButtonAnimation
# 需要导入模块: import sdl2 [as 别名]
# 或者: from sdl2 import SDL_Delay [as 别名]
def flashButtonAnimation(color, animationSpeed=50):
if color == YELLOW:
sound = BEEP1
flashColor = BRIGHTYELLOW
rectangle = YELLOWRECT
elif color == BLUE:
sound = BEEP2
flashColor = BRIGHTBLUE
rectangle = BLUERECT
elif color == RED:
sound = BEEP3
flashColor = BRIGHTRED
rectangle = REDRECT
elif color == GREEN:
sound = BEEP4
flashColor = BRIGHTGREEN
rectangle = GREENRECT
r, g, b, a = flashColor
channel = sdlmixer.Mix_PlayChannel(-1, sound, 0)
for start, end, step in ((0, 255, 1), (255, 0, -1)): # animation loop
for alpha in range(start, end, animationSpeed * step):
handle_events()
REN.fill(rectangle, color)
REN.fill(rectangle, (r,g,b,alpha))
REN.present()
sdl2.SDL_Delay(1000//FPS)
REN.fill(rectangle, color)
REN.present()
示例9: changeBackgroundAnimation
# 需要导入模块: import sdl2 [as 别名]
# 或者: from sdl2 import SDL_Delay [as 别名]
def changeBackgroundAnimation(animationSpeed=40):
global BGCOLOR
newBgColor = sdl2.ext.Color(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
r, g, b, a = newBgColor
for alpha in range(0, 255, animationSpeed): # animation loop
handle_events()
REN.fill((0, 0, WINDOWWIDTH, WINDOWHEIGHT), (r,g,b,alpha))
drawButtons() # redraw the buttons on top of the tint
REN.present();
sdl2.SDL_Delay(1000//FPS)
BGCOLOR = newBgColor
示例10: showStartScreen
# 需要导入模块: import sdl2 [as 别名]
# 或者: from sdl2 import SDL_Delay [as 别名]
def showStartScreen():
title1 = SPRITE_FACTORY.from_text("Wormy!", size=100, bg_color=DARKGREEN)
title2 = SPRITE_FACTORY.from_text("Wormy!", size=100, color=GREEN)
#titleSurf1 = titleFont.render('Wormy!', True, WHITE, DARKGREEN)
#titleSurf2 = titleFont.render('Wormy!', True, GREEN)
pressKey = SPRITE_FACTORY.from_text("Press a key to play.", color=DARKGRAY)
pressKey.position = WINDOWWIDTH - 200, WINDOWHEIGHT - 30
degrees1 = 0
degrees2 = 0
win_surf = WINDOW.get_surface()
while True:
REN.clear(BGCOLOR) #fill?
rot_title1p = sdlgfx.rotozoomSurface(title1.surface, degrees1, 1, sdlgfx.SMOOTHING_ON)
rot_title2p = sdlgfx.rotozoomSurface(title2.surface, degrees2, 1, sdlgfx.SMOOTHING_ON)
rot1 = rot_title1p.contents
rot2 = rot_title2p.contents
rect1 = sdl2.rect.SDL_Rect(WINDOWWIDTH//2 - rot1.w//2, WINDOWHEIGHT//2 - rot1.h//2, 0, 0)
rect2 = sdl2.rect.SDL_Rect(WINDOWWIDTH//2 - rot2.w//2, WINDOWHEIGHT//2 - rot2.h//2, 0, 0)
sdl2.SDL_BlitSurface(rot1, None, win_surf, rect1)
sdl2.SDL_BlitSurface(rot2, None, win_surf, rect2)
if check_for_key_press():
return
SPRITE_RENDERER.render(pressKey)
REN.present()
sdl2.SDL_Delay(1000//FPS)
degrees1 += 3 # rotate by 3 degrees each frame
degrees2 += 7 # rotate by 7 degrees each frame
示例11: drawBoxCovers
# 需要导入模块: import sdl2 [as 别名]
# 或者: from sdl2 import SDL_Delay [as 别名]
def drawBoxCovers(ren, board, boxes, coverage):
# Draws boxes being covered/revealed. "boxes" is a list
# of two-item lists, which have the x & y spot of the box.
for box in boxes:
left, top = leftTopCoordsOfBox(box[0], box[1])
ren.fill((left, top, BOXSIZE, BOXSIZE), BGCOLOR)
shape, color = getShapeAndColor(board, box[0], box[1])
drawIcon(ren, shape, color, box[0], box[1])
if coverage > 0: # only draw the cover if there is an coverage
ren.fill((left, top, coverage, BOXSIZE), BOXCOLOR)
ren.present()
sdl2.SDL_Delay(FPS)
示例12: gameWonAnimation
# 需要导入模块: import sdl2 [as 别名]
# 或者: from sdl2 import SDL_Delay [as 别名]
def gameWonAnimation(ren, board):
# flash the background color when the player has won
coveredBoxes = generateRevealedBoxesData(True)
color1 = LIGHTBGCOLOR
color2 = BGCOLOR
for i in range(13):
color1, color2 = color2, color1 # swap colors
ren.clear(color1)
drawBoard(ren, board, coveredBoxes)
ren.present()
sdl2.SDL_Delay(300)
示例13: generateNewPuzzle
# 需要导入模块: import sdl2 [as 别名]
# 或者: from sdl2 import SDL_Delay [as 别名]
def generateNewPuzzle(numSlides):
# From a starting configuration, make numSlides number of moves (and
# animate these moves).
sequence = []
board = getStartingBoard()
drawBoard(board, 'Generating new puzzle...')
sdl2.SDL_Delay(500) # pause 500 milliseconds for effect
lastMove = None
for i in range(numSlides):
move = getRandomMove(board, lastMove)
slideAnimation(board, move, 'Generating new puzzle...', animationSpeed=TILESIZE//3)
sequence.append(move)
lastMove = move
return (board, sequence)
示例14: run
# 需要导入模块: import sdl2 [as 别名]
# 或者: from sdl2 import SDL_Delay [as 别名]
def run():
if sdl2.SDL_Init(sdl2.SDL_INIT_VIDEO) != 0:
print(sdl2.SDL_GetError())
return -1
window = sdl2.SDL_CreateWindow(b"OpenGL demo",
sdl2.SDL_WINDOWPOS_UNDEFINED,
sdl2.SDL_WINDOWPOS_UNDEFINED, 800, 600,
sdl2.SDL_WINDOW_OPENGL)
if not window:
print(sdl2.SDL_GetError())
return -1
context = sdl2.SDL_GL_CreateContext(window)
GL.glMatrixMode(GL.GL_PROJECTION | GL.GL_MODELVIEW)
GL.glLoadIdentity()
GL.glOrtho(-400, 400, 300, -300, 0, 1)
x = 0.0
y = 30.0
event = sdl2.SDL_Event()
running = True
while running:
while sdl2.SDL_PollEvent(ctypes.byref(event)) != 0:
if event.type == sdl2.SDL_QUIT:
running = False
GL.glClearColor(0, 0, 0, 1)
GL.glClear(GL.GL_COLOR_BUFFER_BIT)
GL.glRotatef(10.0, 0.0, 0.0, 1.0)
GL.glBegin(GL.GL_TRIANGLES)
GL.glColor3f(1.0, 0.0, 0.0)
GL.glVertex2f(x, y + 90.0)
GL.glColor3f(0.0, 1.0, 0.0)
GL.glVertex2f(x + 90.0, y - 90.0)
GL.glColor3f(0.0, 0.0, 1.0)
GL.glVertex2f(x - 90.0, y - 90.0)
GL.glEnd()
sdl2.SDL_GL_SwapWindow(window)
sdl2.SDL_Delay(10)
sdl2.SDL_GL_DeleteContext(context)
sdl2.SDL_DestroyWindow(window)
sdl2.SDL_Quit()
return 0
示例15: run
# 需要导入模块: import sdl2 [as 别名]
# 或者: from sdl2 import SDL_Delay [as 别名]
def run():
sdl2.ext.init()
window = sdl2.ext.Window("The Pong Game", size=(800, 600))
window.show()
if "-hardware" in sys.argv:
print("Using hardware acceleration")
renderer = sdl2.ext.Renderer(window)
factory = sdl2.ext.SpriteFactory(sdl2.ext.TEXTURE, renderer=renderer)
else:
print("Using software rendering")
factory = sdl2.ext.SpriteFactory(sdl2.ext.SOFTWARE)
# Create the paddles - we want white ones. To keep it easy enough for us,
# we create a set of surfaces that can be used for Texture- and
# Software-based sprites.
sp_paddle1 = factory.from_color(WHITE, size=(20, 100))
sp_paddle2 = factory.from_color(WHITE, size=(20, 100))
sp_ball = factory.from_color(WHITE, size=(20, 20))
world = sdl2.ext.World()
movement = MovementSystem(0, 0, 800, 600)
collision = CollisionSystem(0, 0, 800, 600)
aicontroller = TrackingAIController(0, 600)
if factory.sprite_type == sdl2.ext.SOFTWARE:
spriterenderer = SoftwareRenderSystem(window)
else:
spriterenderer = TextureRenderSystem(renderer)
world.add_system(aicontroller)
world.add_system(movement)
world.add_system(collision)
world.add_system(spriterenderer)
player1 = Player(world, sp_paddle1, 0, 250)
player2 = Player(world, sp_paddle2, 780, 250, True)
ball = Ball(world, sp_ball, 390, 290)
ball.velocity.vx = -BALL_SPEED
collision.ball = ball
aicontroller.ball = ball
running = True
while running:
for event in sdl2.ext.get_events():
if event.type == sdl2.SDL_QUIT:
running = False
break
if event.type == sdl2.SDL_KEYDOWN:
if event.key.keysym.sym == sdl2.SDLK_UP:
player1.velocity.vy = -PADDLE_SPEED
elif event.key.keysym.sym == sdl2.SDLK_DOWN:
player1.velocity.vy = PADDLE_SPEED
elif event.type == sdl2.SDL_KEYUP:
if event.key.keysym.sym in (sdl2.SDLK_UP, sdl2.SDLK_DOWN):
player1.velocity.vy = 0
sdl2.SDL_Delay(10)
world.process()