Skip to content

Instantly share code, notes, and snippets.

@shiroutosan
Created August 14, 2018 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shiroutosan/c9ac30756783c9c4335f8eb6d3635854 to your computer and use it in GitHub Desktop.
Save shiroutosan/c9ac30756783c9c4335f8eb6d3635854 to your computer and use it in GitHub Desktop.
from pygame.locals import *
import pygame
class player():
def __init__(self,x,y,img):
self.x = x
self.y = y
self.image = pygame.image.load(img)
self.imagelist = self.split_image(self.image)
def split_image(self,image):
"""128x128のキャラクターイメージを32x32の16枚のイメージに分割
分割したイメージを格納したリストを返す"""
imageList = []
dots = 32
for i in range(0, 128, dots):
for j in range(0, 128, dots):
surface = pygame.Surface((dots, dots)) # 32*32のSurfaceを生成
surface.blit(image, (0, 0), (j, i, dots, dots))
surface.set_colorkey(surface.get_at((0, 0)), RLEACCEL)#座標(0,0)の色を透過色に設定
surface.convert()
imageList.append(surface)#リストに追加
return imageList
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment