Bra*_*nel 6 python pygame pygame-surface
我试图使用带有area参数的surface.blits来提高我的代码的性能.当我使用blits的area参数时,我遇到以下错误:
SystemError:'pygame.Surface'对象>的''方法'blits'返回带有错误集的结果.
如果我删除区域参数,blits就像我期望的那样工作.关于我可能做错的任何想法?下面是我的用例和错误的示例代码.
import sys
import random
import pygame
pygame.init()
tilemap = pygame.image.load('pattern.jpg')
tilesize = 64
size = 4
w, h = size*64, size*64
screen = pygame.display.set_mode((w, h))
while True:
screen.fill((0, 0, 0))
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
blit_list = []
for i in range(size):
for j in range(size):
xi, yi = random.randint(0, size), random.randint(0, size)
blit_args = (tilemap, (i*tilesize, j*tilesize),
(xi*tilesize, yi*tilesize, tilesize, tilesize))
# calling screen.blit here works correctly
screen.blit(*blit_args)
blit_list.append(blit_args)
# instead of using multiple blit calls above, calling screen.blits here fails
# remove the area argument (3rd arg) from each blit_arg tuple works
# screen.blits(blit_list)
pygame.display.flip()
# wait a second
pygame.time.wait(1000)
Run Code Online (Sandbox Code Playgroud)
这是我使用的图像(https://www.behance.net/gallery/19447645/Summer-patterns):
这是 C 代码中的一个错误。在surface.c第2258行,surf_blits有以下测试:
if (dest->flags & SDL_OPENGL &&\n !(dest->flags & (SDL_OPENGLBLIT & ~SDL_OPENGL))) {\n bliterrornum = BLITS_ERR_NO_OPENGL_SURF;\n goto bliterror;\n }\nRun Code Online (Sandbox Code Playgroud)\n\n而在surface.c 第 2118 行中,surf_blit代码为:
#if IS_SDLv1\n if (dest->flags & SDL_OPENGL &&\n !(dest->flags & (SDL_OPENGLBLIT & ~SDL_OPENGL)))\n return RAISE(pgExc_SDLError,\n "Cannot blit to OPENGL Surfaces (OPENGLBLIT is ok)");\n#endif /* IS_SDLv1 */\nRun Code Online (Sandbox Code Playgroud)\n\n注意#if IS_SDLv1.
问题似乎来自于SDL_OPENGLBLIT现已弃用的。
\n\n\n不要使用已弃用的 SDL_OPENGLBLIT 模式,该模式过去允许同时传输和使用 OpenGL。由于多种原因,该标志已被弃用。在许多情况下,使用 SDL_OPENGLBLIT 可能会破坏您的 OpenGL 状态。
\n
不幸的是,我不是 OpenGL 专家,无法进一步解释。希望有人能给出更准确的答案。
\n\n我确信我可以提高BLITS_ERR_SEQUENCE_SURF之前加注(例如,通过将 apygame.Rect作为第一个对象blit_args),但我无法BLITS_ERR_INVALID_DESTINATION在之后加注。
这让我觉得上面几行出了什么问题。
\n\n编辑
\n\n我可以确认如果我添加#if IS_SDLv1上面的测试并重新编译 pygame,它就可以工作。但不知道为什么!\xe2\x98\xba
| 归档时间: |
|
| 查看次数: |
308 次 |
| 最近记录: |