相关疑难解决方法(0)

如何使用Pygame围绕其中心旋转图像?

我一直试图在使用中围绕其中心旋转图像,pygame.transform.rotate()但它不起作用.特别是挂起的部分是rot_image = rot_image.subsurface(rot_rect).copy().我得到了例外:

ValueError: subsurface rectangle outside surface area

以下是用于旋转图像的代码:

def rot_center(image, angle):
    """rotate an image while keeping its center and size"""
    orig_rect = image.get_rect()
    rot_image = pygame.transform.rotate(image, angle)
    rot_rect = orig_rect.copy()
    rot_rect.center = rot_image.get_rect().center
    rot_image = rot_image.subsurface(rot_rect).copy()
    return rot_image
Run Code Online (Sandbox Code Playgroud)

python pygame rotation

13
推荐指数
4
解决办法
2万
查看次数

我怎样才能让我的子弹看起来像是从我的枪尖中出来?

在此处输入图片说明在此处输入图片说明我有在我的子弹不看问题喜欢他们来了我的枪出来,他们看起来像他们来的球员身体出视频,你可以在视频中看到它拍摄别的地方或者它的枪了同样的事情左侧它向上射击很好,但向下射击很糟糕VIDEO

在此处输入图片说明

我试着把我的枪调到 120,但结果是一切都对右侧有效,而不对左侧VIDEO 有效,因为你可以看到它只是小故障

我的弹丸课

class projectile(object):
   def __init__(self, x, y, dirx, diry, color):
       self.x = x
       self.y = y
       self.dirx = dirx
       self.diry = diry
       self.slash = pygame.image.load("round.png")
       self.slash = pygame.transform.scale(self.slash,(self.slash.get_width()//2,self.slash.get_height()//2))
       self.rect  = self.slash.get_rect()
       self.rect.topleft = ( self.x, self.y )
       self.speed = 18
       self.color = color
       self.hitbox = (self.x + -18, self.y, 46,60)



Run Code Online (Sandbox Code Playgroud)

我的射弹是如何附加的


        if event.type == pygame.MOUSEBUTTONDOWN:           
                    
                    # this is for the bullets
            if len(bullets) < 3:
                if box1.health > 25:
                    mousex, mousey …
Run Code Online (Sandbox Code Playgroud)

python pygame

8
推荐指数
1
解决办法
256
查看次数

使用pygame旋转图像

我是pygame的新手,想要编写一些代码,只需每10秒将图像旋转90度.我的代码看起来像这样:

    import pygame
    import time
    from pygame.locals import *
    pygame.init()
    display_surf = pygame.display.set_mode((1200, 1200))
    image_surf = pygame.image.load("/home/tempuser/Pictures/desktop.png").convert()
    imagerect = image_surf.get_rect() 
    display_surf.blit(image_surf,(640, 480))
    pygame.display.flip()
    start = time.time()
    new = time.time()
    while True:
        end = time.time()
        if end - start > 30:
            break
        elif end - new  > 10:
            print "rotating"
            new = time.time()
            pygame.transform.rotate(image_surf,90)
            pygame.display.flip()
Run Code Online (Sandbox Code Playgroud)

此代码不起作用,即图像不旋转,尽管每10秒钟在终端中打印"旋转".有人能告诉我我做错了什么吗?

python pygame python-2.7

7
推荐指数
1
解决办法
2万
查看次数

如何设置pygame.transform.rotate()的轴心点(旋转中心)?

我想围绕中心以外的点旋转矩形.到目前为止我的代码是:

import pygame

pygame.init()
w = 640
h = 480
degree = 45
screen = pygame.display.set_mode((w, h))

surf = pygame.Surface((25, 100))
surf.fill((255, 255, 255))
surf.set_colorkey((255, 0, 0))
bigger = pygame.Rect(0, 0, 25, 100)
pygame.draw.rect(surf, (100, 0, 0), bigger)
rotatedSurf = pygame.transform.rotate(surf, degree)
screen.blit(rotatedSurf, (400, 300))

running = True
while running:
    event = pygame.event.poll()
    if event.type == pygame.QUIT:
        running = False
    pygame.display.flip()
Run Code Online (Sandbox Code Playgroud)

我可以改变度数以获得不同的旋转但旋转大约是中心.我想将矩形中心以外的点设置为旋转点.

python pygame rotation python-2.7

6
推荐指数
4
解决办法
3710
查看次数

如何在图像尺寸变大时绕其中心旋转图像(在 Pygame 中)

我加载了一张图像,我希望它绕其中心旋转,同时其比例越来越大。我最初知道如何围绕图像的中心旋转图像,但如果比例变大,我很难计算位置。我尝试过,但图像只是“跳舞”,而不是停留在中心。

python pygame image rotation scale

2
推荐指数
1
解决办法
1631
查看次数

标签 统计

pygame ×5

python ×5

rotation ×3

python-2.7 ×2

image ×1

scale ×1