我想杀死我的精灵。怎么杀掉它?
import pygame as pygame , sys,time
pygame.init()
size = (700,500)
window_game = pygame.display.set_mode(size)
_run_ = True
white = (255,255,255)
mouse_pos = pygame.mouse.get_pos()
class mySprite(pygame.sprite.Sprite):
def __init__ (self,cord_x,cord_y,picture,colorkey):
super().__init__()
self.image = pygame.Surface([0,0])
self.image = pygame.image.load(picture)
self.image.set_colorkey(colorkey)
self.rect = self.image.get_rect()
self.rect.center = [cord_x,cord_y]
self.kill()
placeSP_group = pygame.sprite.Group()
Clock = pygame.time.Clock()
FPS = 500
while _run_:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.QUIT
sys.exit()
mouse_pos = pygame.mouse.get_pos()
placeSP = [mySprite(mouse_pos[0],mouse_pos[1],'sp_1.png',white)]
pygame.display.flip()
placeSP_group.draw(window_game)
placeSP_group.add(placeSP[:])
Clock.tick(FPS)
现在我希望我的精灵被杀死并获得新的鼠标位置 和 window_game.fill('black') 不起作用,你能做些什么来修复它,请告诉我...... 我想要的是每次鼠标移动时我不想杀死最后一个精灵并使用当前精灵位置创建另一个精灵。
import pygame as pygame , sys,time
pygame.init()
size = (700,500)
window_game = pygame.display.set_mode(size)
_run_ = True
white = (255,255,255)
mouse_pos = pygame.mouse.get_pos()
class mySprite(pygame.sprite.Sprite):
def __init__ (self,cord_x,cord_y,picture,colorkey):
super().__init__()
self.image = pygame.Surface([0,0])
self.image = pygame.image.load(picture)
self.image.set_colorkey(colorkey)
self.rect = self.image.get_rect()
self.rect.center = [cord_x,cord_y]
self.kill()
placeSP_group = pygame.sprite.Group()
Clock = pygame.time.Clock()
FPS = 500
while _run_:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.QUIT
sys.exit()
mouse_pos = pygame.mouse.get_pos()
placeSP = [mySprite(mouse_pos[0],mouse_pos[1],'sp_1.png',white)]
pygame.display.flip()
placeSP_group.draw(window_game)
placeSP_group.add(placeSP[:])
Clock.tick(FPS)
now i want that my sprite get's killed and get the new mouse position
and window_game.fill('black')
dosen't work is there any thing you can do to fix it pls tell me...
what i wan't is every time my mouse moves i wan't kill the last sprite and create the other one with the current sprite pos.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在错误的时刻使用了
kill()
。当
Sprite
位于Group
内时,kill()
起作用,但您首先创建尝试使用kill 的
,然后将此精灵添加到Sprite
()Group
。您应该首先创建
Sprite
,然后添加到Group
,然后对Sprite
中的第一个Sprite
运行kill()
>Group但普通的
Group
不必保持精灵有序并更好地使用完整的工作代码。它显示 5 个跟随鼠标的精灵。
You use
kill()
in wrong moment.kill()
works whenSprite
is insideGroup
but you first createSprite
which try to usekill()
and later you add this sprite toGroup
.You should first create
Sprite
, next add toGroup
and later runkill()
for firstSprite
inGroup
but normal
Group
doesn't have to keep sprites in order and better useFull working code. It display 5 sprites which follow mouse.