我正在使用spritemanager,并试图在Renpy中进行边缘锁定的侧滚轴运动。但是,当按下向左和向右箭头键然后迅速松开时,会出现问题:
如果一次又一次按下并释放左箭头键和右箭头键,这两个问题都不会发生(并且可以按预期工作)。
def engine_updater(st):
if store.time_counter:
store.time_counter -= .001
if store.time_counter <= 0.0:
store.time_counter = None
store.player_sprites.append(Character_Sprite())
g_s = store.player_sprites
if g_s:
for sprite in g_s[:]:
sprite.update()
sprite.movement()
return .001
def engine_event(ev, x, y, st):
if ev.type == KEYDOWN and ev.key in BUTTONS:
pressed = pygame.key.get_pressed()
if pressed[u_arrow] and not u_arrow in store.control_flags:
store.control_flags.append(u_arrow)
if pressed[d_arrow] and not d_arrow in store.control_flags:
store.control_flags.append(d_arrow)
if pressed[l_arrow] and not l_arrow in store.control_flags:
store.control_flags.append(l_arrow)
store.spriteFlip = True
store.charWalk = True
elif pressed[r_arrow] and not r_arrow in store.control_flags:
store.control_flags.append(r_arrow)
store.spriteFlip = False
store.charWalk = True
if ev.type == KEYUP and ev.key in BUTTONS:
if ev.key in store.control_flags:
store.control_flags.remove(ev.key)
在Character_Sprite类中:
def movement(self):
if store.control_flags:
if l_arrow in store.control_flags:
self.dist -= self.move_amt
if self.dist > -175 or self.dist < -2993:
self.x -= self.move_amt
store.charCentered = False
else:
self.x -= 0
store.charCentered = True
elif r_arrow in store.control_flags:
self.dist += self.move_amt
if self.dist > -175 or self.dist < -2993:
self.x += self.move_amt
store.charCentered = False
else:
self.x += 0
store.charCentered = True
def update(self):
if self.delay_frames > 0:
self.delay_frames -= 1
return
self.delay_frames = self.max_delay
self.frame_number += 1
if self.frame_number >= self.max_frames:
self.frame_number = 0
self.refresh_sprite()
def refresh_sprite(self):
self.tx, self.ty, self.tz = self.show.x, self.show.y, self.show.zorder
self.show.destroy()
self.sprite = self.frame_list[self.frame_number]
if spriteFlip == True:
self.sprite = im.Flip(self.sprite,True,False)
self.show = MNG.create(self.sprite)
self.show.x, self.show.y, self.show.zorder = self.tx, self.ty, self.tz
为了方便查看,我删除了一些代码,但是如果需要,我可以显示更多代码。