Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Pygame密钥。set_repeat()不起作用_Python_Pygame - Fatal编程技术网

Python Pygame密钥。set_repeat()不起作用

Python Pygame密钥。set_repeat()不起作用,python,pygame,Python,Pygame,我正在尝试编写一个简单的地图编辑器,但是pygame.set_repeat()遇到了一个问题,我在while循环之前设置了它,但也在while循环中尝试了它,它似乎什么都没做 我检查了其他线程,但没有发现任何有用的东西。 有人能提供一些意见吗 import pygame import math import sys import os import os.path from pygame.locals import * from classes.tile_sprites import spri

我正在尝试编写一个简单的地图编辑器,但是pygame.set_repeat()遇到了一个问题,我在while循环之前设置了它,但也在while循环中尝试了它,它似乎什么都没做

我检查了其他线程,但没有发现任何有用的东西。 有人能提供一些意见吗

import pygame
import math
import sys
import os
import os.path

from pygame.locals import *
from classes.tile_sprites import sprites
from classes.tile_sprites import buttons

class MainCode:

    def main(self):
        size = width, height = 800, 600
        display = pygame.display.set_mode(size)
        fps_clock = pygame.time.Clock()

        button_location = "../resources/images/buttons"
        icon_location = "../resources/images/icons"

        surface_type = {"track":os.path.join(icon_location, "track.png"),
                         "dirt":os.path.join(icon_location, "dirt.png"),
                         "grass":os.path.join(icon_location, "grass")}

        incline_type = {"steep_incline":os.path.join(icon_location, "steep_incline.png"),
                        "moderate_incline":os.path.join(icon_location,"moderate_incline.png"),
                        "flat":os.path.join(icon_location, "flat.png"),
                        "moderate_decline":os.path.join(icon_location, "moderate_decline.png"),
                        "steep_decline":os.path.join(icon_location, "steep_decline.png")}

        surface_selections = ["track", "dirt", "grass"]
        incline_selections = ["steep_incline", "moderate_incline", "flat", "moderate_decline", "steed_decline"]

        tile_group = pygame.sprite.Group()
        button_group = pygame.sprite.Group()
        selected_group = pygame.sprite.GroupSingle()

        sbl = buttons((25, 25), (0, 255, 0), "left")
        sbl.rect.x, sbl.rect.y = 0, 0
        sbr = buttons((25, 25), (0, 255, 0), "right")
        sbr.rect.x, sbl.rect.y = 100, 0
        ibl = buttons((25, 25), (0, 255, 0), "left")
        ibl.rect.x, ibl.rect.y = 0, 100
        ibr = buttons((25, 25), (0, 255, 0), "right")
        ibr.rect.x, ibr.rect.y = 100, 100
        to_add = [sbl, sbr, ibl, ibr]
        button_group = self.pygame_group_add_many(to_add, button_group)

        pygame.key.set_repeat(1, 1000000000)

        while 1:
            for event in pygame.event.get():
                if event.type == QUIT:
                    pygame.quit()
                    sys.exit()
            mouse = pygame.mouse.get_pos()
            key = pygame.key.get_pressed()
            if key[K_DOWN]:
                print "down"

            display.fill((0, 0, 0))
            tile_group.draw(display)
            button_group.draw(display)
            pygame.display.flip()
            fps_clock.tick(30)

    def pygame_group_add_many(self, items_to_add, group):
        for each in items_to_add:
            group.add(each)
        return group

if __name__ == "__main__":
    MainCode().main()
get_pressed()
if键[K_DOWN]:
表示您一直按住
K_DOWN
,并且没有“取消按下”
get\u pressed()
set\u repeat()
无关

set\u repeat()
处理事件

当您按住
K_down

if event.type == KEYDOWN:
    if event.key == K_DOWN:
        print "event down"
如果您添加
set\u repeat(11000)
当您按住
K\u down时,它将每隔1000毫秒打印一次“event down”

if event.type == KEYDOWN:
    if event.key == K_DOWN:
        print "event down"
完整示例:

import pygame
from pygame.locals import *

pygame.init()

display = pygame.display.set_mode( (800,600) )

pygame.key.set_repeat(1,1000) # add/remove this line

running = True        
while running:

    for event in pygame.event.get():
        if event.type == KEYDOWN:
            if event.key == K_ESCAPE:
                running = False
            elif event.key == K_DOWN:
                print "EVENT DOWN"

pygame.quit()
get_pressed()
if键[K_DOWN]:
表示您一直按住
K_DOWN
,并且没有“取消按下”
get\u pressed()
set\u repeat()
无关

set\u repeat()
处理事件

当您按住
K_down

if event.type == KEYDOWN:
    if event.key == K_DOWN:
        print "event down"
如果您添加
set\u repeat(11000)
当您按住
K\u down时,它将每隔1000毫秒打印一次“event down”

if event.type == KEYDOWN:
    if event.key == K_DOWN:
        print "event down"
完整示例:

import pygame
from pygame.locals import *

pygame.init()

display = pygame.display.set_mode( (800,600) )

pygame.key.set_repeat(1,1000) # add/remove this line

running = True        
while running:

    for event in pygame.event.get():
        if event.type == KEYDOWN:
            if event.key == K_ESCAPE:
                running = False
            elif event.key == K_DOWN:
                print "EVENT DOWN"

pygame.quit()
get_pressed()
if键[K_DOWN]:
表示您一直按住
K_DOWN
,并且没有“取消按下”
get\u pressed()
set\u repeat()
无关

set\u repeat()
处理事件

当您按住
K_down

if event.type == KEYDOWN:
    if event.key == K_DOWN:
        print "event down"
如果您添加
set\u repeat(11000)
当您按住
K\u down时,它将每隔1000毫秒打印一次“event down”

if event.type == KEYDOWN:
    if event.key == K_DOWN:
        print "event down"
完整示例:

import pygame
from pygame.locals import *

pygame.init()

display = pygame.display.set_mode( (800,600) )

pygame.key.set_repeat(1,1000) # add/remove this line

running = True        
while running:

    for event in pygame.event.get():
        if event.type == KEYDOWN:
            if event.key == K_ESCAPE:
                running = False
            elif event.key == K_DOWN:
                print "EVENT DOWN"

pygame.quit()
get_pressed()
if键[K_DOWN]:
表示您一直按住
K_DOWN
,并且没有“取消按下”
get\u pressed()
set\u repeat()
无关

set\u repeat()
处理事件

当您按住
K_down

if event.type == KEYDOWN:
    if event.key == K_DOWN:
        print "event down"
如果您添加
set\u repeat(11000)
当您按住
K\u down时,它将每隔1000毫秒打印一次“event down”

if event.type == KEYDOWN:
    if event.key == K_DOWN:
        print "event down"
完整示例:

import pygame
from pygame.locals import *

pygame.init()

display = pygame.display.set_mode( (800,600) )

pygame.key.set_repeat(1,1000) # add/remove this line

running = True        
while running:

    for event in pygame.event.get():
        if event.type == KEYDOWN:
            if event.key == K_ESCAPE:
                running = False
            elif event.key == K_DOWN:
                print "EVENT DOWN"

pygame.quit()

我不清楚你的问题。。。你的实际输出是什么,预期输出是什么?最终,这将用于选择项目,在我刚刚打印的时候,当按键发生时,据我所知,通过设置keyrepeat,我应该能够改变发生这种情况的速度,但不会改变。你试着把这变成一个简短的,自包含、可编译、示例?如果您删除所有不需要重现问题的代码(同时您甚至可以自己解决问题!),我们将更容易在这里提供帮助:-)我不清楚您的问题。。。你的实际输出是什么,预期输出是什么?最终,这将用于选择项目,在我刚刚打印的时候,当按键发生时,据我所知,通过设置keyrepeat,我应该能够改变发生这种情况的速度,但不会改变。你试着把这变成一个简短的,自包含、可编译、示例?如果您删除所有不需要重现问题的代码(同时您甚至可以自己解决问题!),我们将更容易在这里提供帮助:-)我不清楚您的问题。。。你的实际输出是什么,预期输出是什么?最终,这将用于选择项目,在我刚刚打印的时候,当按键发生时,据我所知,通过设置keyrepeat,我应该能够改变发生这种情况的速度,但不会改变。你试着把这变成一个简短的,自包含、可编译、示例?如果您删除所有不需要重现问题的代码(同时您甚至可以自己解决问题!),我们将更容易在这里提供帮助:-)我不清楚您的问题。。。你的实际输出是什么,预期输出是什么?最终,这将用于选择项目,在我刚刚打印的时候,当按键发生时,据我所知,通过设置keyrepeat,我应该能够改变发生这种情况的速度,但不会改变。你试着把这变成一个简短的,自包含、可编译、示例?如果您删除了重现问题所不需要的所有代码(同时您甚至可以自己解决问题!),我们将更容易在这里提供帮助:-)