我正在尝试制作纸牌游戏.现在显示它我使用具有功能的Allegro API:
al_draw_rotated_bitmap(OBJECT_TO_ROTATE,CENTER_X,CENTER_Y,X
,Y,DEGREES_TO_ROTATE_IN_RADIANS);
Run Code Online (Sandbox Code Playgroud)
所以有了这个,我可以轻松地让我的粉丝效果.问题在于知道哪个卡在鼠标下面.为此,我想到做多边形碰撞测试.我只是不确定如何旋转卡上的4个点来构成多边形.我基本上需要和Allegro做同样的操作.
例如,卡的4个点是:
card.x
card.y
card.x + card.width
card.y + card.height
Run Code Online (Sandbox Code Playgroud)
我需要一个像以下的功能:
POINT rotate_point(float cx,float cy,float angle,POINT p)
{
}
Run Code Online (Sandbox Code Playgroud)
谢谢
我一直试图在使用中围绕其中心旋转图像,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)