本文整理匯總了Python中sdl2.SDLK_d方法的典型用法代碼示例。如果您正苦於以下問題:Python sdl2.SDLK_d方法的具體用法?Python sdl2.SDLK_d怎麽用?Python sdl2.SDLK_d使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sdl2
的用法示例。
在下文中一共展示了sdl2.SDLK_d方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _on_key_down_event
# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDLK_d [as 別名]
def _on_key_down_event(self, event, scene_state):
"""Event 'on key down'."""
code = event.keysym.sym
modifier = event.keysym.mod
if modifier == sdl2.KMOD_NONE:
if code == sdl2.SDLK_SPACE:
self._listen_for_navigation = True
elif code == sdl2.SDLK_d:
self.particle_display = (
(self.particle_display + 1) % (ParticleDisplay._LAST + 1))
elif code == sdl2.SDLK_f:
self._fit_view(scene_state)
elif code == sdl2.SDLK_g:
self.show_grid = not self.show_grid
elif code == sdl2.SDLK_r:
self._reset_view()
示例2: run
# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDLK_d [as 別名]
def run(self):
next(self.model.tick)
self.keydict = { #key mapped here
sdl2.SDLK_a:[False,False, 0, -1], #left
sdl2.SDLK_d:[False,False, 0, 1], #right
sdl2.SDLK_w:[False,False, 1, -1], #up
sdl2.SDLK_s:[False,False, 1, 1], #down
sdl2.SDLK_l:[False,False, 2, 1], #A
sdl2.SDLK_j:[False,False, 2, -1], #B
sdl2.SDLK_i:[False,False, 3, 1]} #Hold
self.intup = [0,0,0,0] #(left/right), (up/down), (b/a), (hold)
running = True
d = sdl2.timer.SDL_GetTicks()
t = d
tick = 0
while running:
tick += 1
events = sdl2.ext.get_events()
for event in events:
if event.type == sdl2.SDL_QUIT:
running=False
break
if event.type == sdl2.SDL_KEYDOWN:
if event.key.keysym.sym in self.keydict.keys():
self.keydict[event.key.keysym.sym][0] = True
if event.type == sdl2.SDL_KEYUP:
if event.key.keysym.sym in self.keydict.keys():
self.keydict[event.key.keysym.sym][0] = False
for i, d in enumerate(self.intup):
if d != 0:
self.intup[i] += ( 1 if d > 0 else -1 )
for key in self.keydict.keys():
if self.keydict[key][0] != self.keydict[key][1]:
if self.keydict[key][0]:
self.intup[self.keydict[key][2]] = self.keydict[key][3]
elif self.intup[self.keydict[key][2]] * self.keydict[key][3] > 0:
self.intup[self.keydict[key][2]] = 0
self.keydict[key][1] = self.keydict[key][0]
self.model.tick.send(self.intup)
next(self.view.render)
next(self.audio.player)
d = sdl2.timer.SDL_GetTicks()
sdl2.timer.SDL_Delay(max((tick*1000)//self.framerate-d+t, 0))
return