3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

pygameでウィンドウ内の見た目を一括拡大

Last updated at Posted at 2019-08-08

個人的に詰まったのでメモ。

やりたいこと

  • 内部的には320x240で動いてるけど描画は640x480にしたい、みたいな状況。
  • ドットゲーで必要。
  • 各画像のSurfaceを2倍にする方法は何か違う。

コード

  • PlayerクラスはSpriteを継承したやつ。
  • SpriteGroupでdrawしてるけどSurfaceのblitでも同じ方法で行けると思います。
main.py
import pygame
from pygame.locals import *
import sys

from player import Player

def main():
    pygame.init()
    pygame.display.set_mode((640, 480)) # 最終的に描画したいサイズでdisplaySurface作成
    pygame.display.set_caption("ゲームだぞよ")
    
    screen = pygame.Surface((320, 240)) # 動かしたいサイズで別のSurface作成
    clock = pygame.time.Clock()
    
    playerGroup = pygame.sprite.Group()
    playerGroup.add(Player(0, 0))
    
    while True:
        screen.fill((0, 0, 0))
        
        playerGroup.update()
        playerGroup.draw(screen) #別のSurfaceの方に描画する
        
        pygame.transform.scale(screen, (640, 480), pygame.display.get_surface()) # 描画してたSurfaceの方を拡大し、その描画先をdisplaySurfaceにする

        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()

        pygame.display.update()        

        clock.tick(60) # fps制御
        
if __name__  == "__main__":
    main()

参考

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?