HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
🥋
Pygame Lecture
/
🐟
002 창 이름, 배경 추가하기
🐟

002 창 이름, 배경 추가하기

1. 실행 코드2. 상세 내용3. 실행화면
 

1. 실행 코드

import pygame as pg pg.init() 화면가로길이 = 600 화면세로길이 = 800 화면 = pg.display.set_mode((화면가로길이, 화면세로길이)) pg.display.set_caption('생선잡기_게임') 배경이미지 = pg.image.load("img/배경.png") 배경이미지 = pg.transform.scale(배경이미지, (화면가로길이, 화면세로길이)) 화면.blit(배경이미지, (0, 0)) pg.display.update() while True: for 이벤트 in pg.event.get(): if 이벤트.type == pg.QUIT: quit()

2. 상세 내용

pg.display.set_caption('생선잡기_게임') 배경이미지 = pg.image.load("img/배경.png") 배경이미지 = pg.transform.scale(배경이미지, (화면가로길이, 화면세로길이)) 화면.blit(배경이미지, (0, 0)) pg.display.update()
  • pg.display.set_caption(문자열) : 현재 게임 창의 제목을 설정합니다.
  • pg.image.load("이미지 주소") : 해당 주소에 있는 이미지를 불러옵니다. 이 때, Surface라는 파이게임에서 사용되는 이미지를 표현할 수 있는 객체로 반환합니다.
    • pygame.Surface - pygame v2.0.0.dev15 documentation
      pygame object for representing images Surface((width, height), flags=0, depth=0, masks=None) -> Surface Surface((width, height), flags=0, Surface) -> Surface A pygame Surface is used to represent any image. The Surface has a fixed resolution and pixel format. Surfaces with 8-bit pixels use a color palette to map to 24-bit color.
      pygame.Surface - pygame v2.0.0.dev15 documentation
      https://www.pygame.org/docs/ref/surface.html
      pygame.Surface - pygame v2.0.0.dev15 documentation
  • pg.transform.scale(surface 객체,(가로,세로)) : 객체의 크기를 입력받은 (가로,세로)의 값으로 변경합니다.
    • transform라이브러리의 대해 더 자세히 알고 싶으면 공식홈페이지 Docs를 참고하세요.
    • pygame.transform - pygame v2.0.0.dev15 documentation
      pygame module to transform surfaces A Surface transform is an operation that moves or resizes the pixels. All these functions take a Surface to operate on and return a new Surface with the results. Some of the transforms are considered destructive. These means every time they are performed they lose pixel data.
      pygame.transform - pygame v2.0.0.dev15 documentation
      https://www.pygame.org/docs/ref/transform.html#pygame.transform.scale
      pygame.transform - pygame v2.0.0.dev15 documentation
  • 화면.blit(surface 객체, (X,Y)): 입력받은 X위치, Y위치로 부터 화면에 객체를 추가합니다.
  • pg.display.update() : 화면에 지금까지의 변경사항을 업데이트 합니다. 즉, 화면에 어떠한 객체를 집어 넣고 실행시키면 바로 반영이 되는 것이 아니라 이 함수를 실행시켜야만 적용이 됩니다.

3. 실행화면

 
notion image