求助!!!实在不知道这个background为什么不行
pg.init()ball_image = 'ball.png'
bg_image = 'background.png'
running = True
bg_size = width,height = 1024 , 600
screen = pg.display.set_mode(bg_size)
pg.display.set_caption('Play the ball !')
background = pg.image.load(ball_image).convert_alpha
balls = []
for i in range(5):
position = randint(0,width-64),randint(0,height-64)
speed =
ball = Ball(ball_image,position,speed)
balls.append(ball)
while running:
for event in pg.event.get():
if event.type == QUIT:
sys.exit()
screen.fill((255,255,255))
screen.blit(background,(0,0))
for each in balls:
screen.blit(each.image,each.rect)
Traceback (most recent call last):
File "C:\Users\ASUS\Desktop\main.py", line 53, in <module>
main()
File "C:\Users\ASUS\Desktop\main.py", line 43, in main
screen.blit(background,(0,0))
TypeError: argument 1 must be pygame.Surface, not builtin_function_or_method 第一个参数错了吧
screen.blit(player,(xpos,ypos)) 疾风怪盗 发表于 2020-9-4 15:57
第一个参数错了吧
参数是surface,我其他程序这个可以运行,这个不知的为啥,检查了好几遍了都 阁阁下 发表于 2020-9-4 16:09
参数是surface,我其他程序这个可以运行,这个不知的为啥,检查了好几遍了都
你放出来的是全部代码了?
网上找了下,你这样写好像没错,不知道什么原因
要么你把全部代码放出来看看 疾风怪盗 发表于 2020-9-4 16:16
你放出来的是全部代码了?
网上找了下,你这样写好像没错,不知道什么原因
import pygame as pg
import sys
from pygame.locals import *
from random import *
clock = pg.time.Clock()
class Ball(pg.sprite.Sprite):
def __init__(self,image,position,speed):
pg.sprite.Sprite.__init__(self)
self.image = pg.image.load(image).convert_alpha()
self.rect = self.image.get_rect()
self.rect.left,self.rect.top = position
self.speed = speed
def main():
pg.init()
ball_image = 'ball.png'
bg_image = 'background.png'
running = True
bg_size = width,height = 1024 , 600
screen = pg.display.set_mode(bg_size)
pg.display.set_caption('Play the ball !')
background = pg.image.load(ball_image).convert_alpha
balls = []
for i in range(5):
position = randint(0,width-64),randint(0,height-64)
speed =
ball = Ball(ball_image,position,speed)
balls.append(ball)
while running:
for event in pg.event.get():
if event.type == QUIT:
sys.exit()
screen.fill((255,255,255))
screen.blit(background,(0,0))
for each in balls:
screen.blit(each.image,each.rect)
pg.display.flip()
clock.tick(30)
if __name__ == '__main__':
main()
background = pg.image.load(ball_image).convert_alpha()
这个是个方法吧,加个()就不报错了,但是是静态的,动不了,你是不是还没写完? 疾风怪盗 发表于 2020-9-4 17:02
这个是个方法吧,加个()就不报错了,但是是静态的,动不了,你是不是还没写完?
是静态的,还没设置移动呢。你说的是哪里加个括号 阁阁下 发表于 2020-9-4 17:07
是静态的,还没设置移动呢。你说的是哪里加个括号
def main():
pg.init()
ball_image = 'star02.png'
bg_image = 'backgroudpicture01.jpg'
running = True
bg_size = width, height = 1024, 600
screen = pg.display.set_mode(bg_size)
pg.display.set_caption('Play the ball !')
background = pg.image.load(ball_image).convert_alpha()
最后这里,你在class里加了括号,这里没加 疾风怪盗 发表于 2020-9-4 17:09
最后这里,你在class里加了括号,这里没加
哈哈哈,谢谢,我没看到.convert_alpha后面没有括号。。。。 阁阁下 发表于 2020-9-4 17:54
哈哈哈,谢谢,我没看到.convert_alpha后面没有括号。。。。
如果问题解决了的话,请给个最佳吧{:5_108:}
页:
[1]