Reputation: 45
I'm writing an arcade game with traditional resolution 240 x 320 (vertical screen)
I need to render that to a modern display in real time. This means that I need it to double (1 pixel = 4 on output) or even triple (1 pixel = 9)
I can't simply double scale the sprites because the game movement won't scale with them. (movement won't "snap" to visual scale)
Currently I have a game window that is 480 x 640 pixels.
I'm blitting all game sprites to a 240 x 320 surface, double scaling it and outputting that surface to the window with pygame. The game has slowed down far too much now.
How can all these emulators do nice double scale and triple scales with big clean pixels and pygame not? I thought SDL would be better at 2D rasterization.
Here is the code I currently have:
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)
Upvotes: 0
Views: 1653
Reputation: 464
I found that pygame.transform.scale2x() is in a for loop. Try just using it before pygame.display.update(). If there is more than one bullet, then I see how it could get laggy quickly.
Upvotes: 1