我为pygame添加了连续滚动的背景,以显示效果,就像玩家一直在奔跑一样。它正在工作,但问题是它不是很平稳,几乎没有每秒出现的小故障。我该怎么做才能解决此问题?
在主while循环背景对象的每一帧更新位置中,左侧是5像素,x-5发生在每一帧中
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-397-9bed171c79be> in <module>
----> 1 model = model_fn()
<ipython-input-396-13bc1955a7f2> in model_fn()
1 def model_fn():
2 keras_model = create_compiled_keras_model()
----> 3 return tff.learning.from_compiled_keras_model(keras_model, train)
~/miniconda3/lib/python3.6/site-packages/tensorflow_federated/python/learning/model_utils.py in from_compiled_keras_model(keras_model, dummy_batch)
190 raise ValueError('`keras_model` must be compiled. Use from_keras_model() '
191 'instead.')
--> 192 return enhance(_TrainableKerasModel(keras_model, dummy_batch))
193
194
~/miniconda3/lib/python3.6/site-packages/tensorflow_federated/python/learning/model_utils.py in __init__(self, inner_model, dummy_batch)
434 # until the model has been called on input. The work-around is to call
435 # Model.test_on_batch() once before asking for metrics.
--> 436 inner_model.test_on_batch(**dummy_batch)
437 # This must occur after test_on_batch()
438 if len(inner_model.loss_functions) != 1:
TypeError: test_on_batch() argument after ** must be a mapping, not numpy.ndarray
def game_window():
global warningCount, warningText
player_one.isDead = False
gameOver = 20
run = True
while run:
clock.tick(FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == USEREVENT + 2:
r = random.randrange(0, 2)
if r == 0:
enemy_list.append(Enemy(800, 318, 64, 64, GAMESPEED))
else:
spike_list.append(Spike(800, 0, 48, 330))
player_one.eventHandler(event)
for enemy in enemy_list:
enemy.update()
if enemy.x < 0:
enemy_list.pop(enemy_list.index(enemy))
if enemy.falling:
gameOver -= 1
if gameOver <= 0:
warning[0] = 20
warning[1] = 'GAME OVER'
main_window()
for spike in spike_list:
spike.update()
if spike.x < 0:
spike_list.pop(spike_list.index(spike))
if spike.falling:
gameOver -= 1
if gameOver <= 0:
warning[0] = 20
warning[1] = 'GAME OVER'
main_window()
player_one.update()
bg_one.bgUpade()
bg_two.bgUpade()
redrawGameWindow()
def redrawGameWindow():
global warningCount, warningText
bg_one.draw(win)
bg_two.draw(win)
player_one.draw(win)
for enemy in enemy_list:
enemy.draw(win)
for spike in spike_list:
spike.draw(win)
if warning[0] > 0:
text_surface = bitter.render(warning[1], 1, COLOR_RED)
win.blit(text_surface, (int(W / 2 - text_surface.get_width() / 2), 20))
warning[0] -= 1
pygame.display.update()