我正在写一个传统分辨率为240x320(竖屏)的街机游戏
我需要将其实时渲染到现代显示器上。这意味着我需要它加倍(1像素=4输出)甚至三倍(1像素= 9)
我不能简单地双倍缩放精灵,因为游戏移动不会随着它们缩放。(移动不会“捕捉”到视觉比例)
目前我有一个480x640像素的游戏窗口。
我将所有的游戏精灵绘制到一个240 x 320的表面,双倍缩放,然后用pygame将这个表面输出到窗口。游戏现在已经慢了太多了。
所有这些仿真器怎么能用大而干净的像素做漂亮的双倍尺度和三倍尺度,而不是pygame呢?我认为SDL在2D光栅化方面会做得更好。
这是我目前拥有的代码:
import pygame
import sys
import random
from Bullet import Bullet
bullets = []
pygame.init()
fps_clock = pygame.time.Clock()
# Our final window layer
window = pygame.display.set_mode((480, 640))
# This is the layer that gets scaled
render_layer = pygame.Surface((240, 320))
red = (255, 0, 0)
white = (255, 255, 255)
dkred =(127, 0, 0)
counter = 0;
# Sprite resources
bullet_sprite = pygame.image.load("shot1.png")
bullet_sprite2 = pygame.image.load("shot2.png")
while True:
render_layer.fill(dkred)
for i in bullets:
i.tick()
if i.sprite == "bullet_sprite1":
render_layer.blit(bullet_sprite, (i.x - 12, i.y -12))
else:
render_layer.blit(bullet_sprite2, (i.x - 12, i.y -12))
pygame.transform.scale2x(render_layer, window)
if i.x < 0 or i.y < 0 or i.x > 240 or i.y > 320:
i.dead = True
bullets = [x for x in bullets if x.dead == False]
counter += 3.33
for i in range(10):
if i % 2 == 0:
bullets.append(Bullet(120,120,360.0/10*i - counter, 3, -1,
sprite = "bullet_sprite1"))
else:
bullets.append(Bullet(120,120,360.0/10*i - counter, 3, -1,
sprite = "bullet_sprite2"))
for e in pygame.event.get():
if e.type == pygame.QUIT:
pygame.quit()
sys.exit()
if e.type == pygame.KEYDOWN:
if e.key == pygame.K_ESCAPE:
pygame.event.post(pygame.event.Event(pygame.QUIT))
pygame.display.update()
fps_clock.tick(60)
发布于 2014-01-29 02:54:03
我发现pygame.transform.scale2x()在一个for循环中。试着在pygame.display.update()之前使用它。如果有多个子弹头,那么我知道它会很快变得迟缓。
https://stackoverflow.com/questions/21201211
复制相似问题