相关疑难解决方法(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万
查看次数

如何在 Pygame 中围绕偏离中心的支点旋转图像

我想围绕一个支点,这是不是在中心旋转图像表面pygame的
枢轴是图像中的绿色十字:

在此处输入图片说明

我知道游戏窗口中枢轴的位置。我如何在此时跟踪图像并同时围绕该点旋转它。

image = pygame.image.load("boomerang64.png")
pos = (200, 200)
angle = 0

while True:
    # [...]

    rotate_rect, rotate_image = ???? # rotate around green cross by angle 
    surf.blit(rotated_image, rotate_rect)
    angle += 1

    # [...]
Run Code Online (Sandbox Code Playgroud)

python pygame

4
推荐指数
1
解决办法
846
查看次数

如何将图像(播放器)旋转到鼠标方向?

我正在考虑在 pygame 中制作一个 2d 射击游戏,我想让我的玩家(Player_1)指向鼠标方向。我花了几个小时寻找解决方案,并尝试了我能找到的所有解决方案,但没有一个有效,所以你能帮助我吗?这是我的代码:

import pygame, sys, os
from pygame.locals import *
os.environ['SDL_VIDEO_CENTERED'] = '1'
pygame.init()
#Exit settings
def quit():
  pygame.quit()
  sys.quit()
def events():
    for event in pygame.event.get():
        if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):
            quit()

#IDS
CLOCK=pygame.time.Clock()
FPS=120
DS=pygame.display.set_mode((0,0), pygame.FULLSCREEN)
pygame.display.set_caption("Shooting simulator")
W,H=DS.get_size()
P_X=W/2-50
P_Y=H/2-50

#Colors
Red=pygame.Color("#FF0000")
Blue=pygame.Color("#0000FF")
Green=pygame.Color("#00FF00")
Black=pygame.Color("#000000")
White=pygame.Color("#FFFFFF")

#IGT(in game things)
Player_1=pygame.image.load("Img/Player_1.png").convert()

def game_loop():
  while True:
    events()

    DS.fill(White)
    DS.blit(Player_1,(P_X,P_Y))
    pygame.display.flip()
game_loop()
Run Code Online (Sandbox Code Playgroud)

这是我的玩家(Player_1)

我将非常感谢所有的帮助。

python pygame

3
推荐指数
1
解决办法
1969
查看次数

标签 统计

pygame ×3

python ×3

rotation ×1