目前,每次按下一个键时,精灵只会移动1个像素.当按住左或右键时,我怎么能让管道工精灵不断移动?
while running:
setup_background()
spriteimg = plumberright
screen.blit(spriteimg,(x1, y1))
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_UP:
x1 = x1 + 0
y1 = y1 - 1
elif event.key == pygame.K_DOWN:
x1 = x1 + 0
y1 = y1 + 1
elif event.key == pygame.K_LEFT:
x1 = x1 -1
y1 = y1 + 0
elif event.key == pygame.K_RIGHT:
x1 = x1 + 1
y1 = y1 + 0
pygame.display.flip() …Run Code Online (Sandbox Code Playgroud) 我想导入一个精灵表并选择一个精灵.我将如何在Python/pygame中执行此操作?
我正在努力学习使用pygame制作基本游戏.我想以.png格式导入和显示图像.到目前为止,我的尝试是:
import pygame
from pygame.locals import*
pygame.image.load('clouds.png')
white = (255, 64, 64)
w = 640
h = 480
screen = pygame.display.set_mode((w, h))
screen.fill((white))
running = 1
while running:
screen.fill((white))
pygame.display.flip()
Run Code Online (Sandbox Code Playgroud)
Image(clouds.png)与文件位于同一文件夹中.当我尝试运行这个我得到一个错误:
Traceback (most recent call last):
File "C:\Users\Enrique\Dropbox\gamez.py", line 3, in <module>
pygame.image.load('clouds.png')
error: Couldn't open clouds.png
Run Code Online (Sandbox Code Playgroud) 当我关闭程序窗口时,程序冻结,然后我被迫强制退出程序.为什么在单击X /关闭按钮时程序不会关闭.如果重要的话,我也在使用python 2.7.
import pygame
import os, sys
from itertools import *
from oryxsprites import *
from oryxbackground import *
running = True
while running:
backgroundmain()
pygame.display.set_caption('OryxGame')
#pygame.display.set_icon(biggrasstile)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
Run Code Online (Sandbox Code Playgroud) 我正在尝试设置Django Rest Framework身份验证令牌,据我了解,该表authtoken_token应在makemigrations和之后创建migrate。我将rest_framework添加到settings.py:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'Site',
'rest_framework',
'rest_framework.authtoken',
'MySQLdb'
]
REST_FRAMEWORK = {
# Use Django's standard `django.contrib.auth` permissions,
# or allow read-only access for unauthenticated users.
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.IsAdminUser'
],
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.BasicAuthentication',
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.TokenAuthentication',
),
}
Run Code Online (Sandbox Code Playgroud)
迁移命令输出:
'manage.py@MySite > makemigrations Site
"C:\Program Files (x86)\JetBrains\PyCharm 2016.2\bin\runnerw.exe" C:\Python27\python.exe "C:\Program Files (x86)\JetBrains\PyCharm 2016.2\helpers\pycharm\django_manage.py" makemigrations Site "C:/Users/Eric Franzen/PycharmProjects/MySite"
No changes detected in app 'Site'
Process finished with …Run Code Online (Sandbox Code Playgroud) 我想要完成的是第一个文字出现在1秒后.那么2,等等.直到10.然后当时间等于10时,时间减少,所以文字出现在9秒后,然后是8等.
我如何修复此代码以使其正常工作?
错误:
Traceback (most recent call last):
File "C:/Users/Eric/Dropbox/time.py", line 13, in <module>
time.sleep(time)
AttributeError: 'int' object has no attribute 'sleep'
Run Code Online (Sandbox Code Playgroud)
代码 :
import time
x = 1
t = 1
time = t + 1
while x == 1:
print time
if time >=10:
time = t - 1
elif time <= 0:
time = t + 1
time.sleep(time)
Run Code Online (Sandbox Code Playgroud)
编辑:
import time
x = 1
t = 1
time1 = 0
while x == 1:
if time1 == …Run Code Online (Sandbox Code Playgroud)