我试图做一个黑盒子,我可以点击和拖动,但我似乎被卡住了。有人能帮我看看哪里出了问题吗?你知道吗
def main_game():
import pygame
import math
from time import *
pygame.init()
displayWidth = 268
displayHeight = 552
cyan = (0,255,255)
red = (255,0,0)
dark_red = (150,0,0)
black = (0,0,0)
grey = (200,200,200)
dark_cyan = (0,230,230)
my_rect = pygame.Rect([100,100,100,100])
gameDisplay = pygame.display.set_mode((displayWidth,displayHeight))
pygame.display.set_caption('Test')
pygame.display.update()
gameExit = False
主游戏循环:
while not gameExit:
for event in pygame.event.get():
print event
gameDisplay.fill(grey)
pygame.draw.rect(gameDisplay, black, my_rect)
if event.type == pygame.QUIT:
ExitFunction()
pygame.display.update()
if event.type == pygame.MOUSEBUTTONDOWN:
is_inside = my_rect.collidepoint(pygame.mouse.get_pos())
if is_inside == 1:
gameExit = True
DragScreen()
这是我徒劳的尝试之一,我创建了一个新函数,试图将矩形定位到鼠标的坐标。你知道吗
def DragScreen():
import pygame
from time import *
pygame.init()
displayWidth = 268
displayHeight = 552
cyan = (0,255,255)
red = (255,0,0)
dark_red = (150,0,0)
black = (0,0,0)
grey = (200,200,200)
dark_cyan = (0,230,230)
gameDisplay = pygame.display.set_mode((displayWidth, displayHeight))
pygame.display.set_caption('Test')
pygame.display.update()
gameExit = False
while not gameExit:
for event in pygame.event.get():
print event
gameDisplay.fill(grey)
pygame.draw.rect(gameDisplay, black, pygame.mouse.get_pos())
if event.type == pygame.QUIT:
ExitFunction()
我将添加一个pygame.MOUSEBUTTONUP按钮事件停止拖动长方体
pygame.display.update()
我创建了这个函数,只要在调用它时退出即可(工作正常)。你知道吗
def ExitFunction():
import pygame
from time import*
pygame.init()
pygame.quit()
quit()
pygame.quit()
quit()
main_game()
所以基本上,你可以测试点击对象。并将对象移动到鼠标位置:
相关问题 更多 >
编程相关推荐