在Pygame中使用RightClick模糊图像 [英] Blitting An Image With A RightClick in Pygame

查看:81
本文介绍了在Pygame中使用RightClick模糊图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是pygame的新手,我遇到了一些麻烦。我正在制作一个简单的程序,其中有2个精灵。其中一颗精灵在产卵时被锁定到位,并起到固体的作用。另一个是一个球,当它在另一个精灵的顶部产生时,它会反弹,并遵循万有引力定律。这是我的代码:



I'm new to pygame, and I am having some trouble. I am making a simple program where there are 2 sprites. One of the sprites is locked in place upon spawning, and acts as a solid. The other is a ball that when spawned on top of the other sprite, it will bounce, and follow the laws of gravity. Here is my code:

#!/usr/bin/python

import time
import termcolor
import sys
import pygame
import pygame.mixer
from pygame.locals import *

pygame.init()

box = pygame.image.load("blackbox.png")

def gravity(speed):
    speed = x+5
  

white = (255,255,255)
black = (0,0,0)
green = (0,255,0)

loop = 1
while loop == 1:
######TITLE#####
    pygame.display.set_caption("Gravity")

#########Size of screen########
    size = width, height = 1366, 768
    screen = pygame.display.set_mode(size)
    screen.fill(green)
    ######KEY PRESS EVENTS####
    ##GET MOUSE POSITION
    mx, my = pygame.mouse.get_pos()
    #print mx, my
    for event in pygame.event.get():
        if event.type == KEYDOWN:
            if event.key == K_ESCAPE:
                sys.exit()
        
        if event.type == pygame.QUIT:
            sys.exit()
               
        if event.type == MOUSEBUTTONUP:
            if event.button == 3:
                screen.blit(box,(mx,my))
                
    
    screen.blit(box,(100,100))
    pygame.display.flip()



程序运行时除外我试图产生第一个雪碧。如果你有Pygame的基本知识,你知道在动画时屏幕必须更新。它在哪里
说pygame.display.flip()是更新屏幕的行。执行程序时,一切顺利,直到我右键单击。精灵产生,并立即消失。我知道#this是因为背景更新了它。我需要的是一种确保精灵在整个程序中保持可见的方法。


The Program Runs Fine Except When I Try To Spawn The First Sprite. If You Have Basic Knowledge of Pygame, you know that the screen has to update when you are animating. Where it
says pygame.display.flip() is the line that updates the screen. When executing the program, all is well until I right click. The sprite spawns, and immediately disappears. I know that #this is because the background updates over top of it. What I Need is a way to make sure the sprite stays visible through the entire program.

推荐答案

这篇关于在Pygame中使用RightClick模糊图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆