鱼C论坛

 找回密码
 立即注册
查看: 1780|回复: 1

[已解决]裁剪时,第一次点击松开之后,选择的边框没有消失跟着鼠标继续移动

[复制链接]
发表于 2018-4-10 09:54:51 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
import pygame
import sys
from pygame.locals import *
        
pygame.init()

size=width,height=800,600
bg=255,255,255

screen=pygame.display.set_mode(size)
pygame.display.set_caption('frist')

turtle=pygame.image.load('turtle.png')

#0-没有选中 1选中了 2结束选中
push = 0

#0没有拖动  1拖动中 2 结束拖动
pull = 0

position=turtle.get_rect()
position.center=width//2,height//2


push_rect=pygame.Rect(0,0,0,0)

while True:
    for event in pygame.event.get():
        if event.type==pygame.QUIT:
            sys.exit()

        elif event.type==MOUSEBUTTONDOWN:
            if event.button==1:
                #开始选择
                if push ==0 and pull ==0:
                    pos_start=event.pos
                    push=1
                elif push ==2 and pull==0:
                    cap  = screen.subsurface(push_rect).copy()
                    cap_rect=cap.get_rect()
                    pull=1
                elif push==2 and pull==2:
                    push=0
                    pull=0

        elif event.type==MOUSEBUTTONUP:
            if event.button==1:
                #选择完成
                if push == 1 and pull == 0:
                    pos_stop=event.pos
                    push==2
                if push == 2 and pull == 1:
                    pull=2
    screen.fill(bg)
    screen.blit(turtle,position)
               
    if push:
        mouse_pos = pygame.mouse.get_pos()
        if push==1:
            pos_stop=mouse_pos
            push_rect.left,push_rect.top=pos_start
            push_rect.width,push_rect.height=pos_stop[0]-pos_start[0],pos_stop[1]-pos_start[1]
            pygame.draw.rect(screen,(0,0,0),push_rect,1)
            
    if pull:
        if pull==1:
            cap_rect.center=mouse_pos
        screen.blit(cap,cap_rect)





        
    pygame.display.flip()
最佳答案
2018-4-13 19:13:58
elif event.type==MOUSEBUTTONUP:
            if event.button==1:
                #选择完成
                if push == 1 and pull == 0:
                    pos_stop=event.pos
                    push==2
看到这个最后一句你该明白了
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2018-4-13 19:13:58 | 显示全部楼层    本楼为最佳答案   
elif event.type==MOUSEBUTTONUP:
            if event.button==1:
                #选择完成
                if push == 1 and pull == 0:
                    pos_stop=event.pos
                    push==2
看到这个最后一句你该明白了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-4-19 22:41:59 | 显示全部楼层
真的是一不注意就 BUG
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-3-10 08:31

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表