我正在使用pygame编写一个游戏引擎,以便我可以开始构建伪3D游戏,但是,当我尝试运行它时,我一直遇到这个错误。
Invalid destination position for blit.
我曾尝试过强行所有的立场,但我仍然没有得到任何结果。 这是我的代码:
main.py:
import engine
cool = engine.OBJECT("data/cool.png", 600, 300, 10)
while True:
if engine.events() == "up":
engine.camera.zv = 1
if engine.events() == "keyup":
engine.camera.zv = 0
if engine.events() == "quit":
engine.end()
cool.update()
engine.draw()
engine.refresh(engine.WHITE)
这是engine.py
engine.py:
import pygame, time, math, random, os
random.seed(time.time())
BLACK = ( 0, 0, 0)
WHITE = ( 255, 255, 255)
GREEN = ( 0, 255, 0)
RED = ( 255, 0, 0)
BLUE = ( 0, 0, 255)
PI = 3.141592653
size = (1200, 600)
done = False
clock = pygame.time.Clock()
screen = pygame.display.set_mode(size)
pygame.display.set_caption("ENGINE")
class CAMERA(object):
def __init__(self, image, iresize0, iresize1, xpos, ypos, zpos):
self.x = xpos
self.y = ypos
self.z = zpos
self.xv = 0
self.yv = 0
self.zv = 0
if not image == "":
self.image = pygame.image.load(os.path.join(image))
self.image = pygame.transfrom.scale(self.image, (iresize0, iresize1))
self.image.convert()
camera = CAMERA("", 0, 0, 0, 0, 0)
class OBJECT(object):
global camera
def __init__(self, image, xpos, ypos, zpos):
self.x = xpos
self.y = ypos
self.z = zpos
self.image = pygame.image.load(os.path.join(image))
self.image.convert()
def update(self):
global camera
self.x = (self.x) + camera.xv
self.y = (self.y) + camera.yv
self.z = (self.z*camera.z) + camera.zv
if self.z > 0:
self.image = pygame.image.load(os.path.join(image))
self.image = pygame.transform.scale(self.image, int(self.z), int(self.z))
self.image.convert()
def draw(img, pos):
global screen
screen.blit(img, pos)
def events():
for event in pygame.event.get():
if event.type == pygame.QUIT:
return 'quit'
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
return 'left'
if event.key == pygame.K_RIGHT:
return 'right'
if event.key == pygame.K_UP:
return 'up'
if event.key == pygame.K_DOWN:
return 'down'
if event.key == pygame.K_a:
return 'a'
if event.key == pygame.K_b:
return 'b'
if event.key == pygame.K_c:
return 'c'
if event.key == pygame.K_d:
return 'd'
if event.key == pygame.K_e:
return 'e'
if event.key == pygame.K_f:
return 'f'
if event.key == pygame.K_g:
return 'g'
if event.key == pygame.K_h:
return 'h'
if event.key == pygame.K_i:
return 'i'
if event.key == pygame.K_j:
return 'j'
if event.key == pygame.K_k:
return 'k'
if event.key == pygame.K_l:
return 'l'
if event.key == pygame.K_m:
return 'm'
if event.key == pygame.K_n:
return 'n'
if event.key == pygame.K_o:
return 'o'
if event.key == pygame.K_p:
return 'p'
if event.key == pygame.K_q:
return 'q'
if event.key == pygame.K_r:
return 'r'
if event.key == pygame.K_s:
return 's'
if event.key == pygame.K_t:
return 't'
if event.key == pygame.K_u:
return 'u'
if event.key == pygame.K_v:
return 'v'
if event.key == pygame.K_w:
return 'w'
if event.key == pygame.K_x:
return 'x'
if event.key == pygame.K_y:
return 'y'
if event.key == pygame.K_z:
return 'z'
if event.type == pygame.KEYUP:
return 'keyup'
def refresh(backcolor):
global clock, screen
pygame.display.flip()
clock.tick(60)
screen.fill(backcolor)
def end():
pygame.quit()
先谢谢,我。 更多细节
答案 0 :(得分:1)
你试图在一个错误的位置'blit'
确保使用正确的参数调用此函数
def draw(img, pos):
global screen
screen.blit(img, pos)