如何将光标放在我的图像中?|| Pygame错误|||

时间:2014-01-01 06:27:57

标签: python pygame

以下是我遇到问题的代码。我在pygame中创建一个小的基本鼠标跟踪“游戏”,但是我在宽度和高度旁边添加了/ 2 ...鼠标不会到达中心。这是代码。我做错了什么

import pygame, sys
from pygame.locals import *

bg_image = "bg.jpg"
mouse_image = "superball.jpg"

pygame.init()
screen = pygame.display.set_mode((1000, 1000),0,32)

background = pygame.image.load(bg_image).convert()
mouse_c = pygame.image.load(mouse_image).convert_alpha()

while True:
  for event in pygame.event.get():
        if event.type == QUIT:
              pygame.quit()
              sys.exit()
  screen.blit(background, (0,0))

  x,y = pygame.mouse.get_pos()
  x != mouse_c.get_width()/2 
  y != mouse_c.get_height()/2

  screen.blit(mouse_c,(x,y))

  pygame.display.update() 

忽略缩进错误。这是一个复制和粘贴错误

1 个答案:

答案 0 :(得分:1)

在我看来你写的是x!= mouse_c.get_width()/ 2而不是x = mouse_c.get_width()/ 2 与y相同。

只需删除不是'!'来自这两行的符号,它应该工作。 x!= mouse_c.get_width()/ 2是一个比较语句,整个事情将评估为true或false。 x和y将保持不变,因此当您稍后使用它们时,它们仍然是原始值。