就是想.
谢谢.
而我只是把这个放到30个字符,忽略这一点:)
我正在学习 Python 和 Pygame,我制作的第一件事是一个简单的 Snake 游戏。我试图让蛇每 0.25 秒移动一次。这是我循环的代码部分:
while True:
check_for_quit()
clear_screen()
draw_snake()
draw_food()
check_for_direction_change()
move_snake() #How do I make it so that this loop runs at normal speed, but move_snake() only executes once every 0.25 seconds?
pygame.display.update()
Run Code Online (Sandbox Code Playgroud)
我希望所有其他函数都能正常运行,但 move_snake() 每 0.25 秒只发生一次。我查了一下,找到了一些答案,但对于制作第一个 Python 脚本的人来说,它们似乎都太复杂了。
是否有可能实际获得我的代码应该是什么样子的示例,而不仅仅是告诉我需要使用哪个函数?谢谢!
我看了这个,我知道答案可能涉及使用debug_backtrace(),但我正在努力如何使用它或它究竟是做什么.
基本上,如果这是index.php:
<?php
//some code
//some more code
require "functions.php";
print_line();
//some code
print_line();
?>
Run Code Online (Sandbox Code Playgroud)
和functions.php是:
<?php
function print_line(){
$line="[line that this function was called at]";
print "This function was called from line $line of index.php<br />";
}
?>
Run Code Online (Sandbox Code Playgroud)
设置的正确方法是什么,$line以便输出为:
This function was called from line 7 of index.php
This function was called from line 11 of index.php
Run Code Online (Sandbox Code Playgroud) Here's my check_for_pause() function:
#Check if the user is trying to pause the game
def check_for_pause():
keys=pygame.key.get_pressed() #Get status of all keys
if keys[K_SPACE]: #The space bar is held down
global paused #Make global so it can be edited
if paused==True: #It was paused, so unpause it
paused=False
elif paused==False: #It was playing, so pause it
paused=True
#Don't let the main loop continue until the space bar has been released again, otherwise the variable will flicker between True and False …Run Code Online (Sandbox Code Playgroud)